@betteroffice/pptx-react 0.1.0 → 0.2.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.
- package/README.md +258 -10
- package/dist/index.d.ts +976 -46
- package/dist/index.js +4 -4
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -1,46 +1,95 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
|
-
import {
|
|
3
|
-
import { PptxFontFace, CollaborationReplica, PptxPresence, PresentationHandle, DeckSnapshot
|
|
4
|
-
import { Translations, TFunction } from '@betteroffice/pptx-i18n';
|
|
2
|
+
import { ComponentType, ReactNode, CSSProperties } from 'react';
|
|
3
|
+
import { ParagraphAlignment, PptxEditRefusal, PptxReadRequest, PptxReadResult, PptxFindRequest, PptxFindResult, PptxEditRequest, PptxValidationResult, PptxEditResult, PptxFontFace, CollaborationReplica, PptxPresence, HitTestResult, PresentationHandle, DeckSnapshot } from '@betteroffice/pptx';
|
|
4
|
+
import { TranslationKey, Translations, TFunction } from '@betteroffice/pptx-i18n';
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
6
|
+
/**
|
|
7
|
+
* A value that survives `JSON.stringify` / `JSON.parse` unchanged.
|
|
8
|
+
* @experimental
|
|
9
|
+
*/
|
|
10
|
+
type JsonValue = null | boolean | number | string | readonly JsonValue[] | {
|
|
11
|
+
readonly [key: string]: JsonValue;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* A machine-readable code with a localized explanation for people.
|
|
15
|
+
* @experimental
|
|
16
|
+
*/
|
|
17
|
+
interface CommandReason<Code extends string = string> {
|
|
18
|
+
code: Code;
|
|
19
|
+
message: string;
|
|
20
20
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
/**
|
|
22
|
+
* Serializable availability of one editor command. A disabled command always
|
|
23
|
+
* says why; branch on `disabledReason.code`, show `disabledReason.message`.
|
|
24
|
+
* @experimental
|
|
25
|
+
*/
|
|
26
|
+
type CommandState<Value extends JsonValue = JsonValue, Code extends string = string> = {
|
|
27
|
+
/** Toggle state; `'mixed'` when the selection disagrees. */
|
|
28
|
+
active?: boolean | 'mixed';
|
|
29
|
+
/** The command's current value, such as the selected style or font size. */
|
|
30
|
+
value?: Value;
|
|
31
|
+
} & ({
|
|
32
|
+
enabled: true;
|
|
33
|
+
disabledReason?: never;
|
|
34
|
+
} | {
|
|
35
|
+
enabled: false;
|
|
36
|
+
disabledReason: CommandReason<Code>;
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Plugin DTOs shared by the formats' editor plugin hosts. Clients, selections, anchors, layouts
|
|
41
|
+
* and command maps stay format-owned; these shapes fix grants, lifecycle metadata and refusals.
|
|
42
|
+
*/
|
|
43
|
+
|
|
44
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
45
|
+
/**
|
|
46
|
+
* What a host lets one plugin do. Without a grant a plugin reads, validates and navigates only.
|
|
47
|
+
* Built-in commands need their id listed; mutating ones also need `document: 'write'`.
|
|
48
|
+
*/
|
|
49
|
+
type PluginGrant<CommandId extends string> = {
|
|
50
|
+
commands?: readonly CommandId[];
|
|
51
|
+
} & ({
|
|
52
|
+
document?: 'read';
|
|
53
|
+
editBatches?: never;
|
|
54
|
+
untrackedHistory?: never;
|
|
55
|
+
} | {
|
|
56
|
+
document: 'write';
|
|
57
|
+
/** Allows applying edit batches. */
|
|
58
|
+
editBatches?: true;
|
|
59
|
+
/** Allows batches with `history: 'none'`. */
|
|
60
|
+
untrackedHistory?: true;
|
|
61
|
+
});
|
|
62
|
+
/** Why a plugin's cleanups run. */
|
|
63
|
+
type PluginCleanupReason = 'removed' | 'document-replaced' | 'definition-replaced' | 'unmounted' | 'failed';
|
|
64
|
+
/** `attached`: the plugin was added while a document was open. */
|
|
65
|
+
type PluginLoadReason = 'loaded' | 'replaced' | 'attached';
|
|
66
|
+
type PluginFailureCode = 'plugin-unavailable' | 'document-replaced' | 'aborted' | 'permission-denied' | 'read-only' | 'input-failed' | 'unsupported-policy' | 'plugin-failed';
|
|
67
|
+
/** A plugin client call refused before it reached the document. */
|
|
68
|
+
interface PluginRefusal<Code extends string = PluginFailureCode> {
|
|
69
|
+
ok: false;
|
|
70
|
+
failure: CommandReason<Code>;
|
|
26
71
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
className?: string;
|
|
35
|
-
/** Download name for the save button; falls back to `presentation.pptx`. */
|
|
36
|
-
fileName?: string;
|
|
37
|
-
onReady?: (api: PptxEditorApi) => void;
|
|
38
|
-
onChange?: (snapshot: DeckSnapshot) => void;
|
|
39
|
-
onError?: (error: Error) => void;
|
|
40
|
-
/** Receives the saved bytes; without it, saving downloads the file. */
|
|
41
|
-
onSave?: (bytes: Uint8Array) => void;
|
|
72
|
+
type PluginErrorPhase = 'definition' | 'initialize' | 'event' | 'render' | 'command-state' | 'command' | 'cleanup' | 'action';
|
|
73
|
+
/** A plugin failure reported to the host; `generation` is null outside a document. */
|
|
74
|
+
interface PluginError<Phase extends string = PluginErrorPhase> {
|
|
75
|
+
pluginId: string;
|
|
76
|
+
generation: string | null;
|
|
77
|
+
phase: Phase;
|
|
78
|
+
error: unknown;
|
|
42
79
|
}
|
|
43
|
-
|
|
80
|
+
/**
|
|
81
|
+
* Outcome of a contributed command. Failure codes are the plugin's own, and a refused edit batch
|
|
82
|
+
* can be returned as-is, keeping its structured failure.
|
|
83
|
+
*/
|
|
84
|
+
type PluginCommandResult<Status extends string = string, Refusal extends {
|
|
85
|
+
ok: false;
|
|
86
|
+
} = never> = {
|
|
87
|
+
ok: true;
|
|
88
|
+
status: Status;
|
|
89
|
+
} | {
|
|
90
|
+
ok: false;
|
|
91
|
+
failure: CommandReason;
|
|
92
|
+
} | Refusal;
|
|
44
93
|
|
|
45
94
|
declare const SHAPE_PRESETS: readonly [{
|
|
46
95
|
readonly geometry: "rect";
|
|
@@ -126,6 +175,7 @@ interface ShapeFormatting {
|
|
|
126
175
|
strokeWidthPt?: number | null;
|
|
127
176
|
adjustments?: Record<string, number>;
|
|
128
177
|
}
|
|
178
|
+
type ShapeZOrder = 'front' | 'forward' | 'backward' | 'back';
|
|
129
179
|
type ShapeFormattingAction = {
|
|
130
180
|
type: 'fillColor';
|
|
131
181
|
value: string | null;
|
|
@@ -139,19 +189,689 @@ type ShapeFormattingAction = {
|
|
|
139
189
|
type: 'adjust';
|
|
140
190
|
name: string;
|
|
141
191
|
value: number;
|
|
192
|
+
} | {
|
|
193
|
+
type: 'zOrder';
|
|
194
|
+
value: ShapeZOrder;
|
|
142
195
|
};
|
|
143
196
|
interface SlideLayoutOption {
|
|
144
197
|
partPath: string | null;
|
|
145
198
|
label?: string;
|
|
146
199
|
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* A paint-order move of the selected object among its siblings.
|
|
203
|
+
* @experimental
|
|
204
|
+
*/
|
|
205
|
+
type PptxZOrderMove = 'front' | 'forward' | 'backward' | 'back';
|
|
206
|
+
/**
|
|
207
|
+
* Arguments of every PPTX editor command, keyed by command id.
|
|
208
|
+
* @experimental
|
|
209
|
+
*/
|
|
210
|
+
interface PptxCommandArgs {
|
|
211
|
+
bold: null;
|
|
212
|
+
italic: null;
|
|
213
|
+
underline: null;
|
|
214
|
+
fontFamily: {
|
|
215
|
+
family: string;
|
|
216
|
+
};
|
|
217
|
+
/** Size in points, 1 to 400. */
|
|
218
|
+
fontSize: {
|
|
219
|
+
points: number;
|
|
220
|
+
};
|
|
221
|
+
fontSizeStep: {
|
|
222
|
+
direction: 'increase' | 'decrease';
|
|
223
|
+
};
|
|
224
|
+
/** `#rrggbb`. */
|
|
225
|
+
textColor: {
|
|
226
|
+
color: string;
|
|
227
|
+
};
|
|
228
|
+
alignment: {
|
|
229
|
+
value: ParagraphAlignment;
|
|
230
|
+
};
|
|
231
|
+
/** Omit the layout to reuse the current slide's; `null` inserts without one. */
|
|
232
|
+
insertSlide: {
|
|
233
|
+
layoutPartPath?: string | null;
|
|
234
|
+
};
|
|
235
|
+
insertImage: null;
|
|
236
|
+
/** Selects, or arms text-box or `shape:<preset>` placement on the canvas. */
|
|
237
|
+
tool: {
|
|
238
|
+
value: PptxEditorTool;
|
|
239
|
+
};
|
|
240
|
+
/** `#rrggbb`; `null` removes the fill. */
|
|
241
|
+
shapeFill: {
|
|
242
|
+
color: string | null;
|
|
243
|
+
};
|
|
244
|
+
/** `#rrggbb`; `null` removes the outline. */
|
|
245
|
+
shapeStrokeColor: {
|
|
246
|
+
color: string | null;
|
|
247
|
+
};
|
|
248
|
+
/** Outline width in points; `null` removes the outline. */
|
|
249
|
+
shapeStrokeWidth: {
|
|
250
|
+
points: number | null;
|
|
251
|
+
};
|
|
252
|
+
/** An adjustment of the selected shape, as a fraction of its range. */
|
|
253
|
+
shapeAdjustment: {
|
|
254
|
+
name: string;
|
|
255
|
+
value: number;
|
|
256
|
+
};
|
|
257
|
+
zOrder: {
|
|
258
|
+
value: PptxZOrderMove;
|
|
259
|
+
};
|
|
260
|
+
save: null;
|
|
261
|
+
exportPng: null;
|
|
262
|
+
slideshow: null;
|
|
263
|
+
undo: null;
|
|
264
|
+
redo: null;
|
|
265
|
+
/** 1 is 100%, from 0.25 to 4; `'fit'` fits the slide to the window. */
|
|
266
|
+
zoom: {
|
|
267
|
+
scale: number | 'fit';
|
|
268
|
+
};
|
|
269
|
+
/** `null` toggles the panel. */
|
|
270
|
+
proposalsPanel: {
|
|
271
|
+
open: boolean;
|
|
272
|
+
} | null;
|
|
273
|
+
proposalSelect: {
|
|
274
|
+
proposalId: string;
|
|
275
|
+
};
|
|
276
|
+
/** Shows the selected proposal's changes on the canvas, or the editable slide. */
|
|
277
|
+
proposalDiff: {
|
|
278
|
+
enabled: boolean;
|
|
279
|
+
};
|
|
280
|
+
/** `force` applies a proposal whose targets changed after it was made. */
|
|
281
|
+
proposalAccept: {
|
|
282
|
+
proposalId: string;
|
|
283
|
+
force?: boolean;
|
|
284
|
+
};
|
|
285
|
+
proposalReject: {
|
|
286
|
+
proposalId: string;
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
/** @experimental */
|
|
290
|
+
type PptxCommandId = keyof PptxCommandArgs;
|
|
291
|
+
/**
|
|
292
|
+
* Commands presented as a choice between options.
|
|
293
|
+
* @experimental
|
|
294
|
+
*/
|
|
295
|
+
type PptxSelectCommandId = 'fontFamily' | 'fontSize' | 'alignment' | 'insertSlide' | 'tool' | 'shapeStrokeWidth' | 'shapeAdjustment' | 'zoom' | 'proposalSelect';
|
|
296
|
+
/**
|
|
297
|
+
* Current values reported in {@link PptxCommandState.value}, keyed by command id.
|
|
298
|
+
* @experimental
|
|
299
|
+
*/
|
|
300
|
+
interface PptxCommandValues {
|
|
301
|
+
bold: null;
|
|
302
|
+
italic: null;
|
|
303
|
+
underline: null;
|
|
304
|
+
/** `null` when the selection mixes families. */
|
|
305
|
+
fontFamily: string | null;
|
|
306
|
+
/** Points; `null` when the selection mixes sizes. */
|
|
307
|
+
fontSize: number | null;
|
|
308
|
+
fontSizeStep: null;
|
|
309
|
+
/** `#rrggbb`; `null` when the selection mixes colors. */
|
|
310
|
+
textColor: string | null;
|
|
311
|
+
/** `null` when the selected paragraphs differ. */
|
|
312
|
+
alignment: ParagraphAlignment | null;
|
|
313
|
+
/** The current slide's layout part. */
|
|
314
|
+
insertSlide: string | null;
|
|
315
|
+
insertImage: null;
|
|
316
|
+
tool: PptxEditorTool;
|
|
317
|
+
/** `#rrggbb`; `null` without a fill. */
|
|
318
|
+
shapeFill: string | null;
|
|
319
|
+
/** `#rrggbb`; `null` without an outline. */
|
|
320
|
+
shapeStrokeColor: string | null;
|
|
321
|
+
/** Points; `null` without an outline. */
|
|
322
|
+
shapeStrokeWidth: number | null;
|
|
323
|
+
/** The shape's primary adjustment; `null` when it has none. */
|
|
324
|
+
shapeAdjustment: {
|
|
325
|
+
name: string;
|
|
326
|
+
value: number;
|
|
327
|
+
} | null;
|
|
328
|
+
zOrder: null;
|
|
329
|
+
save: null;
|
|
330
|
+
exportPng: null;
|
|
331
|
+
slideshow: null;
|
|
332
|
+
undo: null;
|
|
333
|
+
redo: null;
|
|
334
|
+
zoom: PptxZoom;
|
|
335
|
+
/** Whether the proposals panel is open. */
|
|
336
|
+
proposalsPanel: boolean;
|
|
337
|
+
/** The proposal shown on the canvas. */
|
|
338
|
+
proposalSelect: string | null;
|
|
339
|
+
/** Whether the canvas shows the selected proposal's changes. */
|
|
340
|
+
proposalDiff: boolean;
|
|
341
|
+
proposalAccept: null;
|
|
342
|
+
proposalReject: null;
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* Why a command is unavailable.
|
|
346
|
+
* @experimental
|
|
347
|
+
*/
|
|
348
|
+
type PptxCommandDisabledCode = 'editor-unavailable' | 'document-loading' | 'no-document' | 'read-only' | 'nothing-to-undo' | 'nothing-to-redo' | 'text-selection-required' | 'shape-required' | 'slide-required' | 'unsupported-selection' | 'invalid-layout' | 'invalid-adjustment' | 'z-order-boundary' | 'review-active'
|
|
349
|
+
/** The canvas diff of a proposal has not painted yet; reported by the canvas review control. */
|
|
350
|
+
| 'preview-pending'
|
|
351
|
+
/** The canvas diff of a proposal could not be laid out; reported by the canvas review control. */
|
|
352
|
+
| 'preview-failed' | 'proposal-stale' | 'proposal-not-found' | 'proposals-unavailable' | 'host-disabled' | 'unsupported-command' | 'invalid-arguments' | 'permission-denied' | 'unsupported-policy' | 'plugin-unavailable';
|
|
353
|
+
/**
|
|
354
|
+
* Why an executed command did not complete.
|
|
355
|
+
* @experimental
|
|
356
|
+
*/
|
|
357
|
+
type PptxCommandFailureCode = PptxCommandDisabledCode | 'input-failed' | 'document-replaced' | 'target-changed' | 'gesture-active' | 'command-failed' | 'aborted';
|
|
358
|
+
/**
|
|
359
|
+
* One choice of a selector command.
|
|
360
|
+
* @experimental
|
|
361
|
+
*/
|
|
362
|
+
interface PptxCommandOption<K extends PptxCommandId = PptxCommandId> {
|
|
363
|
+
args: PptxCommandArgs[K];
|
|
364
|
+
label: string;
|
|
365
|
+
/** Whether this choice is available and current, as `getState(id, args)` reports it. */
|
|
366
|
+
state: CommandState<never, PptxCommandDisabledCode>;
|
|
367
|
+
}
|
|
368
|
+
/**
|
|
369
|
+
* Serializable state of one PPTX command. Without arguments it describes the
|
|
370
|
+
* control, including its choices; with arguments, that one choice.
|
|
371
|
+
* @experimental
|
|
372
|
+
*/
|
|
373
|
+
type PptxCommandState<K extends PptxCommandId = PptxCommandId> = CommandState<PptxCommandValues[K], PptxCommandDisabledCode> & {
|
|
374
|
+
/** Choices a selector presents, in display order. */
|
|
375
|
+
options?: readonly PptxCommandOption<K>[];
|
|
376
|
+
};
|
|
377
|
+
/**
|
|
378
|
+
* A keyboard binding; `Mod` is Cmd on macOS and Ctrl elsewhere.
|
|
379
|
+
* @experimental
|
|
380
|
+
*/
|
|
381
|
+
interface PptxCommandShortcut<K extends PptxCommandId = PptxCommandId> {
|
|
382
|
+
chord: string;
|
|
383
|
+
args: PptxCommandArgs[K];
|
|
384
|
+
}
|
|
385
|
+
/**
|
|
386
|
+
* Static, serializable description of a command.
|
|
387
|
+
* @experimental
|
|
388
|
+
*/
|
|
389
|
+
interface PptxCommandDescriptor<K extends PptxCommandId = PptxCommandId> {
|
|
390
|
+
id: K;
|
|
391
|
+
labelKey: TranslationKey;
|
|
392
|
+
mutatesDocument: boolean;
|
|
393
|
+
shortcuts: readonly PptxCommandShortcut<K>[];
|
|
394
|
+
}
|
|
395
|
+
/** @experimental */
|
|
396
|
+
type PptxCommandStatus = 'executed' | 'noop' | 'opened' | 'requested';
|
|
397
|
+
/**
|
|
398
|
+
* Outcome of {@link PptxCommandStore.execute}: `executed` changed something,
|
|
399
|
+
* `noop` was valid but changed nothing, `opened` showed a picker or panel,
|
|
400
|
+
* and `requested` handed the change to the host.
|
|
401
|
+
* @experimental
|
|
402
|
+
*/
|
|
403
|
+
type PptxCommandResult = {
|
|
404
|
+
ok: true;
|
|
405
|
+
status: PptxCommandStatus;
|
|
406
|
+
} | {
|
|
407
|
+
ok: false;
|
|
408
|
+
failure: CommandReason<PptxCommandFailureCode>;
|
|
409
|
+
};
|
|
410
|
+
/**
|
|
411
|
+
* A command a plugin contributes, registered as `plugin:<pluginId>/<localId>`.
|
|
412
|
+
* @experimental
|
|
413
|
+
*/
|
|
414
|
+
type PptxPluginCommandId = `plugin:${string}/${string}`;
|
|
415
|
+
/**
|
|
416
|
+
* Static description of a contributed command.
|
|
417
|
+
* @experimental
|
|
418
|
+
*/
|
|
419
|
+
interface PptxPluginCommandDescriptor {
|
|
420
|
+
id: PptxPluginCommandId;
|
|
421
|
+
label: string;
|
|
422
|
+
mutatesDocument: boolean;
|
|
423
|
+
shortcuts: readonly {
|
|
424
|
+
chord: string;
|
|
425
|
+
args: null;
|
|
426
|
+
}[];
|
|
427
|
+
}
|
|
428
|
+
/**
|
|
429
|
+
* State of a contributed command; the plugin chooses its own disabled codes.
|
|
430
|
+
* @experimental
|
|
431
|
+
*/
|
|
432
|
+
type PptxPluginCommandState = CommandState;
|
|
433
|
+
/**
|
|
434
|
+
* Outcome of a contributed command: a plugin-defined failure, or a refused edit batch as-is.
|
|
435
|
+
*
|
|
436
|
+
* @experimental The plugin API may change in minor releases.
|
|
437
|
+
*/
|
|
438
|
+
type PptxPluginCommandResult = PluginCommandResult<PptxCommandStatus, PptxEditRefusal>;
|
|
439
|
+
/**
|
|
440
|
+
* The command authority of one editor, shared by built-in and host chrome.
|
|
441
|
+
* @experimental
|
|
442
|
+
*/
|
|
443
|
+
interface PptxCommandStore {
|
|
444
|
+
getDescriptor<K extends PptxCommandId>(id: K): PptxCommandDescriptor<K>;
|
|
445
|
+
/** Null while no active plugin contributes `id`. */
|
|
446
|
+
getDescriptor(id: PptxPluginCommandId): PptxPluginCommandDescriptor | null;
|
|
447
|
+
/** Snapshots are stable until the state changes; pass `args` to evaluate one option. */
|
|
448
|
+
getState<K extends PptxCommandId>(id: K, args?: PptxCommandArgs[K]): PptxCommandState<K>;
|
|
449
|
+
getState(id: PptxPluginCommandId, args?: null): PptxPluginCommandState;
|
|
450
|
+
subscribe(listener: () => void): () => void;
|
|
451
|
+
/** Runs after input accepted before the call; availability is checked again first. */
|
|
452
|
+
execute<K extends PptxCommandId>(id: K, args: PptxCommandArgs[K]): Promise<PptxCommandResult>;
|
|
453
|
+
/** Runs a contributed command with its plugin's own clients, outside the input queue. */
|
|
454
|
+
execute(id: PptxPluginCommandId, args: null): Promise<PptxPluginCommandResult>;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
/**
|
|
458
|
+
* What the host lets one plugin do. Without a grant a plugin reads, validates and navigates only.
|
|
459
|
+
* Built-in commands need their id listed and, when they mutate, `document: 'write'`; edit
|
|
460
|
+
* batches need `document: 'write'` and `editBatches`, and `history: 'none'` also needs
|
|
461
|
+
* `untrackedHistory`. `readOnly` refuses every write regardless.
|
|
462
|
+
*
|
|
463
|
+
* @experimental The plugin API may change in minor releases.
|
|
464
|
+
*/
|
|
465
|
+
type PptxPluginGrant = PluginGrant<PptxCommandId>;
|
|
466
|
+
type PptxPluginFailureCode = PluginFailureCode;
|
|
467
|
+
/**
|
|
468
|
+
* A client call refused before it reached the presentation.
|
|
469
|
+
*
|
|
470
|
+
* @experimental The plugin API may change in minor releases.
|
|
471
|
+
*/
|
|
472
|
+
type PptxPluginRefusal = PluginRefusal<PptxPluginFailureCode>;
|
|
473
|
+
/**
|
|
474
|
+
* Versioned presentation reads. Each runs after pending input.
|
|
475
|
+
*
|
|
476
|
+
* @experimental The plugin API may change in minor releases.
|
|
477
|
+
*/
|
|
478
|
+
interface PptxPluginReadClient {
|
|
479
|
+
version(): Promise<{
|
|
480
|
+
ok: true;
|
|
481
|
+
version: string;
|
|
482
|
+
} | PptxPluginRefusal>;
|
|
483
|
+
readContent(request?: PptxReadRequest): Promise<PptxReadResult | PptxPluginRefusal>;
|
|
484
|
+
findText(request: PptxFindRequest): Promise<PptxFindResult | PptxPluginRefusal>;
|
|
485
|
+
/** Checks a batch without granting anything; a later apply is checked again. */
|
|
486
|
+
validateEdits(request: PptxEditRequest): Promise<PptxValidationResult | PptxPluginRefusal>;
|
|
487
|
+
}
|
|
488
|
+
/**
|
|
489
|
+
* Granted edit batches; the grant and `readOnly` are checked when the batch applies.
|
|
490
|
+
*
|
|
491
|
+
* @experimental The plugin API may change in minor releases.
|
|
492
|
+
*/
|
|
493
|
+
interface PptxPluginEditClient {
|
|
494
|
+
applyEdits(request: PptxEditRequest): Promise<PptxEditResult | PptxPluginRefusal>;
|
|
495
|
+
}
|
|
496
|
+
/**
|
|
497
|
+
* The editor's commands as this plugin may use them.
|
|
498
|
+
*
|
|
499
|
+
* @experimental The plugin API may change in minor releases.
|
|
500
|
+
*/
|
|
501
|
+
interface PptxPluginCommandClient {
|
|
502
|
+
getDescriptor<K extends PptxCommandId>(id: K): PptxCommandDescriptor<K>;
|
|
503
|
+
getDescriptor(id: PptxPluginCommandId): PptxPluginCommandDescriptor | null;
|
|
504
|
+
getState<K extends PptxCommandId>(id: K, args?: PptxCommandArgs[K]): PptxCommandState<K> | {
|
|
505
|
+
enabled: false;
|
|
506
|
+
disabledReason: PptxPluginRefusal['failure'];
|
|
507
|
+
};
|
|
508
|
+
getState(id: PptxPluginCommandId, args?: null): PptxPluginCommandState;
|
|
509
|
+
subscribe(listener: () => void): () => void;
|
|
510
|
+
execute<K extends PptxCommandId>(id: K, args: PptxCommandArgs[K]): Promise<PptxCommandResult | PptxPluginRefusal>;
|
|
511
|
+
/** Only this plugin's own contributed commands. */
|
|
512
|
+
execute(id: PptxPluginCommandId, args: null): Promise<PptxPluginCommandResult | PptxPluginRefusal>;
|
|
513
|
+
}
|
|
514
|
+
/** A rectangle in the units of the space it is used in. */
|
|
515
|
+
interface PptxPluginRect {
|
|
516
|
+
x: number;
|
|
517
|
+
y: number;
|
|
518
|
+
width: number;
|
|
519
|
+
height: number;
|
|
520
|
+
}
|
|
521
|
+
/** A presented slide frame and the presentation version its pixels show. */
|
|
522
|
+
interface PptxPluginLayout {
|
|
523
|
+
/** Changes with every presented frame, slide or zoom; unrelated to document versions. */
|
|
524
|
+
id: string;
|
|
525
|
+
version: string;
|
|
526
|
+
slideId: string;
|
|
527
|
+
/** One-based display number. */
|
|
528
|
+
slide: number;
|
|
529
|
+
/** The resolved scale, including fit. */
|
|
530
|
+
zoom: number;
|
|
531
|
+
/** Unzoomed slide display-list width, in slide pixels. */
|
|
532
|
+
width: number;
|
|
533
|
+
/** Unzoomed slide display-list height, in slide pixels. */
|
|
534
|
+
height: number;
|
|
535
|
+
}
|
|
536
|
+
/** The current slide and what is selected on it; ids are session-scoped. */
|
|
537
|
+
type PptxPluginSelection = {
|
|
538
|
+
slideId: string;
|
|
539
|
+
/** One-based display number. */
|
|
540
|
+
slide: number;
|
|
541
|
+
target: {
|
|
542
|
+
kind: 'slide';
|
|
543
|
+
} | {
|
|
544
|
+
kind: 'shape';
|
|
545
|
+
shapeId: string;
|
|
546
|
+
} | {
|
|
547
|
+
kind: 'text';
|
|
548
|
+
shapeId: string;
|
|
549
|
+
storyId: string;
|
|
550
|
+
/** UTF-16 story offsets; `focus` may precede `anchor`. */
|
|
551
|
+
anchor: number;
|
|
552
|
+
focus: number;
|
|
553
|
+
};
|
|
554
|
+
} | null;
|
|
555
|
+
interface PptxPluginSnapshot {
|
|
556
|
+
/** The open presentation; changes when a presentation replaces it. */
|
|
557
|
+
generation: string;
|
|
558
|
+
version: string;
|
|
559
|
+
readOnly: boolean;
|
|
560
|
+
grant: PptxPluginGrant;
|
|
561
|
+
selection: PptxPluginSelection;
|
|
562
|
+
/** Null while no presented frame shows `version`. */
|
|
563
|
+
layout: PptxPluginLayout | null;
|
|
564
|
+
}
|
|
565
|
+
/** A hit under the pointer, with the layout it was resolved against. */
|
|
566
|
+
type PptxPluginPointPosition = PptxPointPosition & {
|
|
567
|
+
version: string;
|
|
568
|
+
layoutId: string;
|
|
569
|
+
};
|
|
570
|
+
/**
|
|
571
|
+
* Geometry of the presented slide. Rectangles it returns are in pixels of the unscaled overlay
|
|
572
|
+
* layer; every method returns null once its layout is no longer presented.
|
|
573
|
+
*/
|
|
574
|
+
interface PptxPluginGeometry {
|
|
575
|
+
layout: PptxPluginLayout;
|
|
576
|
+
/**
|
|
577
|
+
* Converts a slide rectangle into overlay pixels: `slide-emu` in EMU from the slide's top left
|
|
578
|
+
* corner, `slide-px` in unzoomed display-list pixels.
|
|
579
|
+
*/
|
|
580
|
+
toOverlayRect(input: {
|
|
581
|
+
space: 'slide-emu' | 'slide-px';
|
|
582
|
+
rect: PptxPluginRect;
|
|
583
|
+
}): PptxPluginRect | null;
|
|
584
|
+
/** The rendered bounds of a shape on the presented slide, group descendants included. */
|
|
585
|
+
getShapeRect(shapeId: string): PptxPluginRect | null;
|
|
586
|
+
/** Client coordinates; null outside slide content or during proposal review. */
|
|
587
|
+
getPositionAtPoint(clientX: number, clientY: number): PptxPluginPointPosition | null;
|
|
588
|
+
}
|
|
589
|
+
type PptxPluginNavigationFailureCode = 'stale-version' | 'missing-target' | 'ambiguous-target' | 'layout-unavailable' | 'unsupported';
|
|
590
|
+
/** @experimental The plugin API may change in minor releases. */
|
|
591
|
+
type PptxPluginNavigationResult = {
|
|
592
|
+
ok: true;
|
|
593
|
+
} | PptxPluginRefusal | {
|
|
594
|
+
ok: false;
|
|
595
|
+
failure: {
|
|
596
|
+
code: PptxPluginNavigationFailureCode;
|
|
597
|
+
message: string;
|
|
598
|
+
};
|
|
599
|
+
};
|
|
600
|
+
interface PptxPluginNavigationOptions {
|
|
601
|
+
/** The version the target was read at; a newer presentation refuses with `stale-version`. */
|
|
602
|
+
expectVersion: string;
|
|
603
|
+
/** Moves keyboard focus to the slide; focus stays where it is by default. */
|
|
604
|
+
focus?: boolean;
|
|
605
|
+
}
|
|
606
|
+
/**
|
|
607
|
+
* Navigation after pending input, against the current presentation.
|
|
608
|
+
*
|
|
609
|
+
* @experimental The plugin API may change in minor releases.
|
|
610
|
+
*/
|
|
611
|
+
interface PptxPluginNavigation {
|
|
612
|
+
goToSlide(target: {
|
|
613
|
+
slideId: string;
|
|
614
|
+
}, options: PptxPluginNavigationOptions): Promise<PptxPluginNavigationResult>;
|
|
615
|
+
selectShape(target: {
|
|
616
|
+
slideId: string;
|
|
617
|
+
shapeId: string;
|
|
618
|
+
}, options: PptxPluginNavigationOptions): Promise<PptxPluginNavigationResult>;
|
|
619
|
+
/** Selects `anchor` to `focus` in UTF-16 story offsets, keeping their direction. */
|
|
620
|
+
selectText(target: {
|
|
621
|
+
slideId: string;
|
|
622
|
+
shapeId: string;
|
|
623
|
+
storyId: string;
|
|
624
|
+
anchor: number;
|
|
625
|
+
focus: number;
|
|
626
|
+
}, options: PptxPluginNavigationOptions): Promise<PptxPluginNavigationResult>;
|
|
627
|
+
}
|
|
628
|
+
/** Lifecycle notifications describe current state; several changes may arrive as one. */
|
|
629
|
+
type PptxPluginEvent = {
|
|
630
|
+
type: 'load';
|
|
631
|
+
generation: string;
|
|
632
|
+
version: string;
|
|
633
|
+
reason: PluginLoadReason;
|
|
634
|
+
} | {
|
|
635
|
+
type: 'document-change';
|
|
636
|
+
generation: string;
|
|
637
|
+
version: string;
|
|
638
|
+
} | {
|
|
639
|
+
type: 'selection-change';
|
|
640
|
+
generation: string;
|
|
641
|
+
version: string;
|
|
642
|
+
selection: PptxPluginSelection;
|
|
643
|
+
} | {
|
|
644
|
+
type: 'mode-change';
|
|
645
|
+
generation: string;
|
|
646
|
+
readOnly: boolean;
|
|
647
|
+
} | {
|
|
648
|
+
type: 'layout-change';
|
|
649
|
+
generation: string;
|
|
650
|
+
layout: PptxPluginLayout | null;
|
|
651
|
+
} | {
|
|
652
|
+
type: 'grants-change';
|
|
653
|
+
generation: string;
|
|
654
|
+
grant: PptxPluginGrant;
|
|
655
|
+
};
|
|
656
|
+
/**
|
|
657
|
+
* What a hook, renderer or action receives. Clients refuse once it is superseded or ended.
|
|
658
|
+
*
|
|
659
|
+
* @experimental The plugin API may change in minor releases.
|
|
660
|
+
*/
|
|
661
|
+
interface PptxPluginContext<S> {
|
|
662
|
+
pluginId: string;
|
|
663
|
+
snapshot: PptxPluginSnapshot;
|
|
664
|
+
readonly state: Readonly<S>;
|
|
665
|
+
/** Aborted when this hook is superseded or the plugin ends. */
|
|
666
|
+
signal: AbortSignal;
|
|
667
|
+
/** Aborted when this activation ends. */
|
|
668
|
+
lifetimeSignal: AbortSignal;
|
|
669
|
+
read: PptxPluginReadClient;
|
|
670
|
+
commands: PptxPluginCommandClient;
|
|
671
|
+
/** Null without an edit batch grant. */
|
|
672
|
+
edits: PptxPluginEditClient | null;
|
|
673
|
+
/** Null while no presented frame shows the current version. */
|
|
674
|
+
geometry: PptxPluginGeometry | null;
|
|
675
|
+
navigation: PptxPluginNavigation;
|
|
676
|
+
/**
|
|
677
|
+
* Replaces the plugin's state. Returns false for a superseded context, an ended plugin, or when
|
|
678
|
+
* the presentation is no longer at `atVersion`, which defaults to `snapshot.version`.
|
|
679
|
+
*/
|
|
680
|
+
setState(next: S | ((previous: S) => S), atVersion?: string): boolean;
|
|
681
|
+
/** Registers a disposer; after the plugin ended it runs at once. */
|
|
682
|
+
onCleanup(cleanup: (reason: PluginCleanupReason) => MaybePromise<void>): void;
|
|
683
|
+
/** Runs an event-handler action with a fresh context, isolating its failure. */
|
|
684
|
+
run(action: (context: PptxPluginContext<S>) => MaybePromise<void>): Promise<void>;
|
|
685
|
+
}
|
|
686
|
+
interface PptxPluginPanel<S> {
|
|
687
|
+
title: string;
|
|
688
|
+
placement: 'left' | 'right' | 'bottom';
|
|
689
|
+
/** Width for side panels, height for the bottom panel, in CSS pixels. */
|
|
690
|
+
preferredSize?: number;
|
|
691
|
+
defaultCollapsed?: boolean;
|
|
692
|
+
render: ComponentType<{
|
|
693
|
+
context: PptxPluginContext<S>;
|
|
694
|
+
width: number;
|
|
695
|
+
height: number;
|
|
696
|
+
}>;
|
|
697
|
+
}
|
|
698
|
+
/** A command registered as `plugin:<pluginId>/<id>`. */
|
|
699
|
+
interface PptxPluginCommand<S> {
|
|
700
|
+
id: string;
|
|
701
|
+
label: string;
|
|
702
|
+
/** Disables the command while read-only; grants nothing. */
|
|
703
|
+
mutatesDocument: boolean;
|
|
704
|
+
/** Chords such as `Mod+Shift+R`; built-in shortcuts take precedence. */
|
|
705
|
+
shortcuts?: readonly string[];
|
|
706
|
+
getState?(context: PptxPluginContext<S>): CommandState;
|
|
707
|
+
execute(context: PptxPluginContext<S>): MaybePromise<PptxPluginCommandResult>;
|
|
708
|
+
}
|
|
709
|
+
/**
|
|
710
|
+
* A plugin. `createState`, renderers and command `getState` must be pure; `initialize`,
|
|
711
|
+
* `onEvent`, command `execute` and `context.run` are managed effects.
|
|
712
|
+
*
|
|
713
|
+
* @experimental The plugin API may change in minor releases.
|
|
714
|
+
*/
|
|
715
|
+
interface PptxPluginDefinition<S> {
|
|
716
|
+
id: string;
|
|
717
|
+
/** Changing it restarts the plugin; other definition changes keep its state. */
|
|
718
|
+
revision?: string | number;
|
|
719
|
+
createState(): S;
|
|
720
|
+
initialize?(context: PptxPluginContext<S>): MaybePromise<void>;
|
|
721
|
+
onEvent?(context: PptxPluginContext<S>, event: PptxPluginEvent): MaybePromise<void>;
|
|
722
|
+
panel?: PptxPluginPanel<S>;
|
|
723
|
+
overlay?: ComponentType<{
|
|
724
|
+
context: PptxPluginContext<S>;
|
|
725
|
+
geometry: PptxPluginGeometry;
|
|
726
|
+
}>;
|
|
727
|
+
commands?: readonly PptxPluginCommand<S>[];
|
|
728
|
+
/** Local command ids, in display order. */
|
|
729
|
+
toolbar?: readonly string[];
|
|
730
|
+
}
|
|
731
|
+
declare const pptxPluginBrand: unique symbol;
|
|
732
|
+
/**
|
|
733
|
+
* An installable plugin, created by `definePptxPlugin`.
|
|
734
|
+
*
|
|
735
|
+
* @experimental The plugin API may change in minor releases.
|
|
736
|
+
*/
|
|
737
|
+
interface PptxPlugin {
|
|
738
|
+
readonly id: string;
|
|
739
|
+
readonly revision?: string | number;
|
|
740
|
+
readonly [pptxPluginBrand]: true;
|
|
741
|
+
}
|
|
742
|
+
type PptxPluginErrorPhase = PluginErrorPhase;
|
|
743
|
+
/**
|
|
744
|
+
* A plugin failure; the failing activation has already been stopped and cleaned up.
|
|
745
|
+
*
|
|
746
|
+
* @experimental The plugin API may change in minor releases.
|
|
747
|
+
*/
|
|
748
|
+
type PptxPluginError = PluginError<PptxPluginErrorPhase>;
|
|
749
|
+
/** @experimental The plugin API may change in minor releases. */
|
|
750
|
+
interface PptxEditorPluginProps {
|
|
751
|
+
/** @experimental The plugin API may change in minor releases. */
|
|
752
|
+
plugins?: readonly PptxPlugin[];
|
|
753
|
+
/**
|
|
754
|
+
* Keyed by plugin id; omitted plugins read, validate and navigate only.
|
|
755
|
+
*
|
|
756
|
+
* @experimental The plugin API may change in minor releases.
|
|
757
|
+
*/
|
|
758
|
+
pluginGrants?: Readonly<Record<string, PptxPluginGrant>>;
|
|
759
|
+
/** @experimental The plugin API may change in minor releases. */
|
|
760
|
+
onPluginError?(error: PptxPluginError): void;
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
interface PptxTextSelection {
|
|
764
|
+
shapeId: string;
|
|
765
|
+
storyId: string;
|
|
766
|
+
anchor: number;
|
|
767
|
+
focus: number;
|
|
768
|
+
focusLine?: number;
|
|
769
|
+
}
|
|
770
|
+
interface PptxTextSelectionTarget {
|
|
771
|
+
/** 1-based slide number. */
|
|
772
|
+
slide: number;
|
|
773
|
+
shapeId: string;
|
|
774
|
+
storyId: string;
|
|
775
|
+
start: number;
|
|
776
|
+
end: number;
|
|
777
|
+
}
|
|
778
|
+
type PptxPointPosition = HitTestResult & {
|
|
779
|
+
slide: number;
|
|
780
|
+
slideId: string;
|
|
781
|
+
};
|
|
782
|
+
interface PptxEditorApi {
|
|
783
|
+
/** Waits for accepted input; rejects during unfinished pointer gestures. */
|
|
784
|
+
flushPendingInput: () => Promise<void>;
|
|
785
|
+
/** Client coordinates; returns null outside slide content. */
|
|
786
|
+
getPositionAtPoint: (clientX: number, clientY: number) => PptxPointPosition | null;
|
|
787
|
+
clearSelection: () => void;
|
|
788
|
+
focus: () => void;
|
|
789
|
+
/** Accepts a 1-based slide number. */
|
|
790
|
+
goToSlide: (slide: number) => boolean;
|
|
791
|
+
handle: PresentationHandle;
|
|
792
|
+
/**
|
|
793
|
+
* The editor's commands, shared by built-in and host chrome; `api.handle` edits bypass them.
|
|
794
|
+
* @experimental
|
|
795
|
+
*/
|
|
796
|
+
readonly commands: PptxCommandStore;
|
|
797
|
+
refresh: () => void;
|
|
798
|
+
refreshProposals: () => void;
|
|
799
|
+
/** Serialize the presentation back to .pptx bytes, edits included. */
|
|
800
|
+
save: () => Uint8Array;
|
|
801
|
+
/** Also navigates to the slide. */
|
|
802
|
+
selectText: (target: PptxTextSelectionTarget) => boolean;
|
|
803
|
+
/** Flushes pending input, then returns the session version. */
|
|
804
|
+
version: () => Promise<string>;
|
|
805
|
+
/** Flushes pending input, then reads slides and story text with the version they were read at. */
|
|
806
|
+
readContent: (request?: PptxReadRequest) => Promise<PptxReadResult>;
|
|
807
|
+
/** Flushes pending input, then searches exactly and case-sensitively. */
|
|
808
|
+
findText: (request: PptxFindRequest) => Promise<PptxFindResult>;
|
|
809
|
+
/** Flushes pending input, then checks a batch without changing anything. */
|
|
810
|
+
validateEdits: (request: PptxEditRequest) => Promise<PptxValidationResult>;
|
|
811
|
+
/**
|
|
812
|
+
* Flushes pending input, then applies every step or none against `expectVersion` and refreshes
|
|
813
|
+
* the editor once. A refusal is data and never rolls back the flushed input. Read-only editors
|
|
814
|
+
* refuse with `read-only`. Rejects when the presentation is replaced while input flushes.
|
|
815
|
+
*/
|
|
816
|
+
applyEdits: (request: PptxEditRequest) => Promise<PptxEditResult>;
|
|
817
|
+
}
|
|
818
|
+
interface PptxEditorCollaborationOptions {
|
|
819
|
+
clientId: number;
|
|
820
|
+
initialUpdate?: Uint8Array;
|
|
821
|
+
onReplica?: (replica: CollaborationReplica | null) => void;
|
|
822
|
+
presence?: PptxPresence;
|
|
823
|
+
}
|
|
824
|
+
interface PptxEditorProps extends PptxEditorPluginProps {
|
|
825
|
+
file?: Uint8Array;
|
|
826
|
+
/** Font faces; equivalent inline arrays do not reopen the presentation. */
|
|
827
|
+
fonts: ReadonlyArray<PptxFontFace>;
|
|
828
|
+
clientId?: number;
|
|
829
|
+
collaboration?: PptxEditorCollaborationOptions;
|
|
830
|
+
i18n?: Translations;
|
|
831
|
+
className?: string;
|
|
832
|
+
/** Download name for the save button; falls back to `presentation.pptx`. */
|
|
833
|
+
fileName?: string;
|
|
834
|
+
/** 1-based; clamped to the deck. */
|
|
835
|
+
initialSlide?: number;
|
|
836
|
+
onReady?: (api: PptxEditorApi) => void;
|
|
837
|
+
onChange?: (snapshot: DeckSnapshot) => void;
|
|
838
|
+
onError?: (error: Error) => void;
|
|
839
|
+
/** Receives the saved bytes; without it, saving downloads the file. */
|
|
840
|
+
onSave?: (bytes: Uint8Array) => void;
|
|
841
|
+
/** Return true for built-in saving; false or void handles/cancels the request. */
|
|
842
|
+
onSaveRequest?: () => boolean | void | Promise<boolean | void>;
|
|
843
|
+
/** Blocks user edits; navigation and selection remain available. */
|
|
844
|
+
readOnly?: boolean;
|
|
845
|
+
/**
|
|
846
|
+
* Replaces the toolbar: omit it for the default controls, pass `null` for
|
|
847
|
+
* none, or pass chrome composed from the toolbar parts, which also renders
|
|
848
|
+
* while `readOnly`. `showToolbar={false}` hides the whole region.
|
|
849
|
+
* @experimental
|
|
850
|
+
*/
|
|
851
|
+
toolbar?: ReactNode;
|
|
852
|
+
/** Shows the toolbar region; defaults to true. */
|
|
853
|
+
showToolbar?: boolean;
|
|
854
|
+
}
|
|
855
|
+
declare function PptxEditor({ i18n, ...props }: PptxEditorProps): react.JSX.Element;
|
|
856
|
+
|
|
857
|
+
/**
|
|
858
|
+
* Props of the legacy toolbar, which shows the state it is given and reports
|
|
859
|
+
* actions through callbacks. Prefer `mode="commands"`, which binds controls to
|
|
860
|
+
* the editor's command store.
|
|
861
|
+
*/
|
|
147
862
|
interface ToolbarProps {
|
|
863
|
+
/** `legacy` (the default outside a command-mode `EditorToolbar`) binds controls to these props. */
|
|
864
|
+
mode?: 'legacy';
|
|
148
865
|
currentFormatting?: SelectionFormatting;
|
|
149
866
|
textSelectionActive?: boolean;
|
|
150
867
|
onFormat?: (action: FormattingAction) => void;
|
|
151
868
|
currentShapeFormatting?: ShapeFormatting;
|
|
152
869
|
shapeSelectionActive?: boolean;
|
|
870
|
+
/** Enables the arrange (z-order) menu for any selected object. */
|
|
871
|
+
shapeArrangeActive?: boolean;
|
|
153
872
|
onShapeFormat?: (action: ShapeFormattingAction) => void;
|
|
154
873
|
onInsertSlide?: (layoutPartPath?: string | null) => void;
|
|
874
|
+
onInsertImage?: () => void;
|
|
155
875
|
slideLayouts?: readonly SlideLayoutOption[];
|
|
156
876
|
currentLayoutPartPath?: string | null;
|
|
157
877
|
onSave?: () => void;
|
|
@@ -169,33 +889,75 @@ interface ToolbarProps {
|
|
|
169
889
|
disabled?: boolean;
|
|
170
890
|
className?: string;
|
|
171
891
|
style?: CSSProperties;
|
|
892
|
+
/** Host controls appended after the default ones. */
|
|
172
893
|
children?: ReactNode;
|
|
173
894
|
}
|
|
174
|
-
|
|
895
|
+
type LegacyStateKey = Exclude<keyof ToolbarProps, 'mode' | 'className' | 'style' | 'children'>;
|
|
896
|
+
/**
|
|
897
|
+
* Props of a toolbar bound to the nearest editor's commands.
|
|
898
|
+
* @experimental
|
|
899
|
+
*/
|
|
900
|
+
type CommandToolbarProps = {
|
|
901
|
+
/** Binds every control to the command store of the nearest editor or `PptxCommandProvider`. */
|
|
902
|
+
mode: 'commands';
|
|
903
|
+
/** The complete arrangement; omit to render the default controls. */
|
|
904
|
+
children?: ReactNode;
|
|
905
|
+
className?: string;
|
|
906
|
+
style?: CSSProperties;
|
|
907
|
+
} & {
|
|
908
|
+
[K in LegacyStateKey]?: never;
|
|
909
|
+
};
|
|
910
|
+
/**
|
|
911
|
+
* The formatting rail, with overflow into an accessible "More" menu. In
|
|
912
|
+
* command mode (explicit, or inherited from `EditorToolbar mode="commands"`)
|
|
913
|
+
* children replace the default controls; in legacy mode they follow them.
|
|
914
|
+
*/
|
|
915
|
+
declare function Toolbar(props: ToolbarProps | CommandToolbarProps): react.JSX.Element;
|
|
175
916
|
|
|
176
917
|
type EditorToolbarProps = ToolbarProps;
|
|
177
918
|
declare const EditorToolbarContext: react.Context<ToolbarProps | null>;
|
|
178
919
|
declare function useEditorToolbar(): ToolbarProps;
|
|
179
920
|
|
|
921
|
+
/**
|
|
922
|
+
* A toolbar region bound to the nearest editor's or `PptxCommandProvider`'s commands.
|
|
923
|
+
* @experimental
|
|
924
|
+
*/
|
|
925
|
+
type EditorToolbarCommandProps = Omit<CommandToolbarProps, 'children'> & {
|
|
926
|
+
/** Compound parts; defaults to the formatting rail with the built-in controls. */
|
|
927
|
+
children?: ReactNode;
|
|
928
|
+
/** Locale when rendered outside the editor; defaults to the editor's. */
|
|
929
|
+
i18n?: Translations;
|
|
930
|
+
};
|
|
180
931
|
interface EditorToolbarComponent {
|
|
181
|
-
(props: EditorToolbarProps & {
|
|
932
|
+
(props: (EditorToolbarProps & {
|
|
182
933
|
children: ReactNode;
|
|
183
|
-
|
|
934
|
+
style?: CSSProperties;
|
|
935
|
+
}) | EditorToolbarCommandProps): React.JSX.Element;
|
|
184
936
|
Toolbar: typeof Toolbar;
|
|
185
937
|
}
|
|
186
938
|
declare const EditorToolbar: EditorToolbarComponent;
|
|
187
939
|
|
|
188
940
|
interface ToolbarButtonProps {
|
|
189
|
-
|
|
941
|
+
/** Pressed state; omit for buttons that are not toggles. */
|
|
942
|
+
active?: boolean | 'mixed';
|
|
190
943
|
disabled?: boolean;
|
|
944
|
+
/** Why the button is disabled; announced and shown on hover. */
|
|
945
|
+
description?: string;
|
|
946
|
+
/** Accessible name and tooltip. */
|
|
191
947
|
title: string;
|
|
948
|
+
/** Keyboard shortcut shown in the tooltip and overflow menu, such as `Ctrl+B`. */
|
|
949
|
+
shortcut?: string;
|
|
192
950
|
onClick?: () => void;
|
|
193
951
|
children: ReactNode;
|
|
952
|
+
className?: string;
|
|
194
953
|
style?: CSSProperties;
|
|
195
954
|
testId?: string;
|
|
196
955
|
ariaExpanded?: boolean;
|
|
956
|
+
/** Label of the overflow-menu entry; defaults to `title`. */
|
|
957
|
+
overflowLabel?: string;
|
|
197
958
|
}
|
|
198
|
-
|
|
959
|
+
/** A toolbar button; at narrow widths it moves into the overflow menu. */
|
|
960
|
+
declare function ToolbarButton(props: ToolbarButtonProps): react.JSX.Element;
|
|
199
961
|
declare function ToolbarGroup({ label, children, style, }: {
|
|
200
962
|
label: string;
|
|
201
963
|
children: ReactNode;
|
|
@@ -207,21 +969,33 @@ interface ToolbarDropdownProps {
|
|
|
207
969
|
trigger: ReactNode;
|
|
208
970
|
children: (close: () => void) => ReactNode;
|
|
209
971
|
disabled?: boolean;
|
|
972
|
+
/** Why the dropdown is disabled; announced and shown on hover. */
|
|
973
|
+
description?: string;
|
|
210
974
|
active?: boolean;
|
|
211
975
|
menuWidth?: number;
|
|
212
976
|
style?: CSSProperties;
|
|
213
977
|
testId?: string;
|
|
978
|
+
/**
|
|
979
|
+
* `menu` for content made of `ToolbarMenuItem`s, `dialog` for other controls.
|
|
980
|
+
* Omitted, it follows the content.
|
|
981
|
+
*/
|
|
982
|
+
popup?: 'menu' | 'dialog';
|
|
214
983
|
}
|
|
215
|
-
|
|
984
|
+
/** A button with a popup; hidden at narrow widths, it opens from the overflow menu. */
|
|
985
|
+
declare function ToolbarDropdown(props: ToolbarDropdownProps): react.JSX.Element;
|
|
216
986
|
interface ToolbarMenuItemProps {
|
|
217
987
|
label: string;
|
|
218
988
|
icon?: ReactNode;
|
|
219
989
|
selected?: boolean;
|
|
990
|
+
/** Presents the item as one choice of several, checked when `selected`. */
|
|
991
|
+
radio?: boolean;
|
|
220
992
|
disabled?: boolean;
|
|
993
|
+
/** Why the item is disabled. */
|
|
994
|
+
description?: string;
|
|
221
995
|
onClick?: () => void;
|
|
222
996
|
close?: () => void;
|
|
223
997
|
}
|
|
224
|
-
declare function ToolbarMenuItem({ label, icon, selected, disabled, onClick, close, }: ToolbarMenuItemProps): react.JSX.Element;
|
|
998
|
+
declare function ToolbarMenuItem({ label, icon, selected, radio, disabled, description, onClick, close, }: ToolbarMenuItemProps): react.JSX.Element;
|
|
225
999
|
declare function ToolbarMenuSeparator(): react.JSX.Element;
|
|
226
1000
|
|
|
227
1001
|
interface LocaleProviderProps {
|
|
@@ -233,4 +1007,160 @@ declare function useTranslation(): {
|
|
|
233
1007
|
t: TFunction;
|
|
234
1008
|
};
|
|
235
1009
|
|
|
236
|
-
|
|
1010
|
+
/** @experimental */
|
|
1011
|
+
interface PptxCommandProviderProps {
|
|
1012
|
+
/** An editor's `api.commands`; `null` until the editor is ready. */
|
|
1013
|
+
commands: PptxCommandStore | null;
|
|
1014
|
+
children?: ReactNode;
|
|
1015
|
+
}
|
|
1016
|
+
/**
|
|
1017
|
+
* Provides one editor's commands to toolbar parts rendered anywhere in the tree.
|
|
1018
|
+
* @experimental
|
|
1019
|
+
*/
|
|
1020
|
+
declare function PptxCommandProvider({ commands, children }: PptxCommandProviderProps): react.JSX.Element;
|
|
1021
|
+
|
|
1022
|
+
/**
|
|
1023
|
+
* The nearest editor's command store.
|
|
1024
|
+
* @experimental
|
|
1025
|
+
*/
|
|
1026
|
+
declare function usePptxCommands(): PptxCommandStore;
|
|
1027
|
+
/**
|
|
1028
|
+
* Subscribes to one command's state, optionally for specific arguments.
|
|
1029
|
+
* @experimental
|
|
1030
|
+
*/
|
|
1031
|
+
declare function usePptxCommandState<K extends PptxCommandId>(id: K, args?: PptxCommandArgs[K]): PptxCommandState<K>;
|
|
1032
|
+
/** Subscribes to a contributed command's state. */
|
|
1033
|
+
declare function usePptxCommandState(id: PptxPluginCommandId, args?: null): PptxPluginCommandState;
|
|
1034
|
+
/**
|
|
1035
|
+
* A command bound to this component, with its localized label and shortcut.
|
|
1036
|
+
* @experimental
|
|
1037
|
+
*/
|
|
1038
|
+
interface PptxBoundCommand<K extends PptxCommandId> {
|
|
1039
|
+
id: K;
|
|
1040
|
+
descriptor: PptxCommandDescriptor<K>;
|
|
1041
|
+
state: PptxCommandState<K>;
|
|
1042
|
+
label: string;
|
|
1043
|
+
/** The keyboard shortcut as people read it on this platform, such as `Ctrl+B`. */
|
|
1044
|
+
shortcut: string | null;
|
|
1045
|
+
/** Executes with `args`, falling back to the arguments bound to the hook. */
|
|
1046
|
+
execute(args?: PptxCommandArgs[K]): Promise<PptxCommandResult>;
|
|
1047
|
+
}
|
|
1048
|
+
/**
|
|
1049
|
+
* A contributed command bound to this component.
|
|
1050
|
+
* @experimental
|
|
1051
|
+
*/
|
|
1052
|
+
interface PptxBoundPluginCommand {
|
|
1053
|
+
id: PptxPluginCommandId;
|
|
1054
|
+
/** Null while no active plugin contributes the command. */
|
|
1055
|
+
descriptor: PptxPluginCommandDescriptor | null;
|
|
1056
|
+
state: PptxPluginCommandState;
|
|
1057
|
+
/** The contributed label, or the id while no plugin contributes it. */
|
|
1058
|
+
label: string;
|
|
1059
|
+
shortcut: string | null;
|
|
1060
|
+
execute(): Promise<PptxPluginCommandResult>;
|
|
1061
|
+
}
|
|
1062
|
+
/**
|
|
1063
|
+
* Binds one command for a custom control.
|
|
1064
|
+
* @experimental
|
|
1065
|
+
*/
|
|
1066
|
+
declare function usePptxCommand<K extends PptxCommandId>(id: K, args?: PptxCommandArgs[K]): PptxBoundCommand<K>;
|
|
1067
|
+
/** Binds a contributed command for a custom control. */
|
|
1068
|
+
declare function usePptxCommand(id: PptxPluginCommandId, args?: null): PptxBoundPluginCommand;
|
|
1069
|
+
|
|
1070
|
+
/**
|
|
1071
|
+
* Arguments a control binds; required when the command cannot run without them.
|
|
1072
|
+
* @experimental
|
|
1073
|
+
*/
|
|
1074
|
+
type ToolbarCommandArgs<K extends PptxCommandId | PptxPluginCommandId> = K extends PptxCommandId ? null extends PptxCommandArgs[K] ? {
|
|
1075
|
+
args?: PptxCommandArgs[K];
|
|
1076
|
+
} : {} extends PptxCommandArgs[K] ? {
|
|
1077
|
+
args?: PptxCommandArgs[K];
|
|
1078
|
+
} : {
|
|
1079
|
+
args: PptxCommandArgs[K];
|
|
1080
|
+
} : {
|
|
1081
|
+
args?: null;
|
|
1082
|
+
};
|
|
1083
|
+
/**
|
|
1084
|
+
* A built-in or contributed command; a contributed one renders nothing while inactive.
|
|
1085
|
+
* @experimental
|
|
1086
|
+
*/
|
|
1087
|
+
type ToolbarCommandButtonProps<K extends PptxCommandId | PptxPluginCommandId> = {
|
|
1088
|
+
id: K;
|
|
1089
|
+
/** Button content; defaults to the command's icon, or its label when it has none. */
|
|
1090
|
+
children?: ReactNode;
|
|
1091
|
+
/** Accessible name; defaults to the localized or contributed command label. */
|
|
1092
|
+
label?: string;
|
|
1093
|
+
className?: string;
|
|
1094
|
+
style?: CSSProperties;
|
|
1095
|
+
} & ToolbarCommandArgs<K>;
|
|
1096
|
+
/** @experimental */
|
|
1097
|
+
interface ToolbarCommandSelectProps<K extends PptxSelectCommandId> {
|
|
1098
|
+
id: K;
|
|
1099
|
+
className?: string;
|
|
1100
|
+
}
|
|
1101
|
+
/**
|
|
1102
|
+
* Commands whose full built-in control chooses their arguments.
|
|
1103
|
+
* @experimental
|
|
1104
|
+
*/
|
|
1105
|
+
type PptxControlCommandId = PptxSelectCommandId | 'textColor' | 'shapeFill' | 'shapeStrokeColor' | 'zOrder' | 'fontSizeStep';
|
|
1106
|
+
/** @experimental */
|
|
1107
|
+
type ToolbarCommandProps<K extends PptxCommandId | PptxPluginCommandId> = {
|
|
1108
|
+
id: K;
|
|
1109
|
+
className?: string;
|
|
1110
|
+
} & (K extends PptxControlCommandId ? {
|
|
1111
|
+
/** Binds arguments; omit to render the command's full built-in control. */
|
|
1112
|
+
args?: PptxCommandArgs[K];
|
|
1113
|
+
} : ToolbarCommandArgs<K>);
|
|
1114
|
+
/**
|
|
1115
|
+
* A button bound to one command, showing its pressed and disabled state.
|
|
1116
|
+
* @experimental
|
|
1117
|
+
*/
|
|
1118
|
+
declare function ToolbarCommandButton<K extends PptxCommandId | PptxPluginCommandId>(props: ToolbarCommandButtonProps<K>): react.JSX.Element | null;
|
|
1119
|
+
/**
|
|
1120
|
+
* The built-in picker of a selector command.
|
|
1121
|
+
* @experimental
|
|
1122
|
+
*/
|
|
1123
|
+
declare function ToolbarCommandSelect<K extends PptxSelectCommandId>({ id, className, }: ToolbarCommandSelectProps<K>): react.JSX.Element;
|
|
1124
|
+
/**
|
|
1125
|
+
* The built-in control of any command, as the default toolbar presents it.
|
|
1126
|
+
* @experimental
|
|
1127
|
+
*/
|
|
1128
|
+
declare function ToolbarCommand<K extends PptxCommandId | PptxPluginCommandId>(props: ToolbarCommandProps<K>): react.JSX.Element;
|
|
1129
|
+
|
|
1130
|
+
/** @experimental */
|
|
1131
|
+
interface ToolbarOverflowProps {
|
|
1132
|
+
/** Label of the menu entry that replaces the content at narrow widths. */
|
|
1133
|
+
label: string;
|
|
1134
|
+
onSelect(): void;
|
|
1135
|
+
disabled?: boolean;
|
|
1136
|
+
/** Why the action is disabled. */
|
|
1137
|
+
description?: string;
|
|
1138
|
+
/** Toggle state for a checkbox entry. */
|
|
1139
|
+
checked?: boolean;
|
|
1140
|
+
children: ReactNode;
|
|
1141
|
+
}
|
|
1142
|
+
/**
|
|
1143
|
+
* Gives arbitrary host content a menu entry, so it can move into the overflow
|
|
1144
|
+
* menu instead of scrolling with the row in a narrow toolbar.
|
|
1145
|
+
* @experimental
|
|
1146
|
+
*/
|
|
1147
|
+
declare function ToolbarOverflow({ label, onSelect, disabled, description, checked, children, }: ToolbarOverflowProps): react.JSX.Element;
|
|
1148
|
+
|
|
1149
|
+
/**
|
|
1150
|
+
* Wraps a plugin for `PptxEditor`'s `plugins` prop. The definition is checked when the editor
|
|
1151
|
+
* installs it; a problem is reported through `onPluginError` and disables only this plugin. Its
|
|
1152
|
+
* panel, commands and toolbar are copied and frozen, so changing them takes a new definition.
|
|
1153
|
+
*
|
|
1154
|
+
* @experimental The plugin API may change in minor releases.
|
|
1155
|
+
*/
|
|
1156
|
+
declare function definePptxPlugin<S>(definition: PptxPluginDefinition<S>): PptxPlugin;
|
|
1157
|
+
|
|
1158
|
+
/**
|
|
1159
|
+
* The toolbar commands installed plugins contribute, in plugin and declaration order. The
|
|
1160
|
+
* default toolbar includes it; place it in replacement chrome to keep those commands reachable.
|
|
1161
|
+
*
|
|
1162
|
+
* @experimental The plugin API may change in minor releases.
|
|
1163
|
+
*/
|
|
1164
|
+
declare function PptxPluginToolbar(): React.ReactElement | null;
|
|
1165
|
+
|
|
1166
|
+
export { type CommandReason, type CommandState, type CommandToolbarProps, EditorToolbar, type EditorToolbarCommandProps, EditorToolbarContext, type EditorToolbarProps, type FormattingAction, type JsonValue, LocaleProvider, type LocaleProviderProps, type MaybePromise, type PluginCleanupReason, type PluginGrant, type PluginLoadReason, type PptxBoundCommand, type PptxBoundPluginCommand, type PptxCommandArgs, type PptxCommandDescriptor, type PptxCommandDisabledCode, type PptxCommandFailureCode, type PptxCommandId, type PptxCommandOption, PptxCommandProvider, type PptxCommandProviderProps, type PptxCommandResult, type PptxCommandShortcut, type PptxCommandState, type PptxCommandStatus, type PptxCommandStore, type PptxCommandValues, type PptxControlCommandId, PptxEditor, type PptxEditorApi, type PptxEditorCollaborationOptions, type PptxEditorPluginProps, type PptxEditorProps, type PptxEditorTool, type PptxPlugin, type PptxPluginCommand, type PptxPluginCommandClient, type PptxPluginCommandDescriptor, type PptxPluginCommandId, type PptxPluginCommandResult, type PptxPluginCommandState, type PptxPluginContext, type PptxPluginDefinition, type PptxPluginEditClient, type PptxPluginError, type PptxPluginErrorPhase, type PptxPluginEvent, type PptxPluginFailureCode, type PptxPluginGeometry, type PptxPluginGrant, type PptxPluginLayout, type PptxPluginNavigation, type PptxPluginNavigationFailureCode, type PptxPluginNavigationOptions, type PptxPluginNavigationResult, type PptxPluginPanel, type PptxPluginPointPosition, type PptxPluginReadClient, type PptxPluginRect, type PptxPluginRefusal, type PptxPluginSelection, type PptxPluginSnapshot, PptxPluginToolbar, type PptxPointPosition, type PptxSelectCommandId, type PptxShapePreset, type PptxTextSelection, type PptxTextSelectionTarget, Toolbar as PptxToolbar, type PptxZOrderMove, type PptxZoom, SHAPE_PRESETS, type SelectionFormatting, type ShapeFormatting, type ShapeFormattingAction, type SlideLayoutOption, Toolbar, ToolbarButton, type ToolbarButtonProps, ToolbarCommand, type ToolbarCommandArgs, ToolbarCommandButton, type ToolbarCommandButtonProps, type ToolbarCommandProps, ToolbarCommandSelect, type ToolbarCommandSelectProps, ToolbarDropdown, type ToolbarDropdownProps, ToolbarGroup, ToolbarMenuItem, type ToolbarMenuItemProps, ToolbarMenuSeparator, ToolbarOverflow, type ToolbarOverflowProps, type ToolbarProps, ToolbarSeparator, definePptxPlugin, useEditorToolbar, usePptxCommand, usePptxCommandState, usePptxCommands, useTranslation };
|