Skip to content

Complete Hooks Reference ​

This is the complete list referenced from the Hooks page: every hook that composes PowerPointViewer internally, grouped by concern. For the small curated subset that has a semver-stable public API, see Hooks -> Public hooks instead.

Internal building blocks

All of the hooks below are importable from pptx-react-viewer/internals, but the name is literal: they are not covered by semver, so signatures, behavior, and existence can change without a major bump. Reach for this entry only when the curated pptx-react-viewer/viewer export and the public PowerPointViewer props/handle genuinely can't do what you need. Pin an exact version if you depend on it.

tsx
import { useViewerState, useEditorHistory } from 'pptx-react-viewer/internals';

Core state & lifecycle ​

HookConcern
useViewerStateComposite state hook (composes core + UI state).
useViewerCoreStateDocument state: slides, selection, canvas size, mode.
useViewerUIStateUI state: panel visibility, dialog flags, toolbar flags.
useDerivedSlideStateComputed visible indexes, sections, master pseudo-slide.
useDerivedElementStateComputed per-element derived state (bounds, handles, z-order).
useContentLifecycleContent sync, dirty tracking, recovery detection wiring.
useLoadContentParses the PPTX buffer on mount via PptxHandler.
useRecoveryDetectionDetects a prior unsaved session to offer recovery.
useAutosavePeriodic autosave scheduling and status.
useSerializeSerializes the current document back to bytes.
useViewerIntegrationTop-level integration: I/O, export, print, pointers, lifecycle.

Editing & history ​

HookConcern
useEditorHistoryUndo/redo snapshot stack with deferred capture during pointer interactions.
useEditorOperationsComposes all editor operations into one result.
useElementOperationsElement create/update/delete primitives.
useElementManipulationMove / resize / rotate / delete elements.
useSectionOperationsSection (slide grouping) create/rename/delete.
useTableOperationsRow/column insert/delete, merge/split cells.
useSlideManagementAdd / delete / duplicate / reorder / hide slides.
useInsertElementsShape / image / text box / table / chart insertion.
useGroupAlignLayerHandlersGroup/ungroup, align/distribute, layer (front/back) operations.
useMergeShapesHandlerBoolean shape merge (union/subtract/intersect/exclude).
usePropertyHandlersProperty-panel change handlers for selected elements.
useThemeHandlersApplying/switching the document's PowerPoint theme.
useThemeSwitchingHigher-level theme switch orchestration (also public, see below).
useLayoutSwitchingSwitching a slide's layout while remapping placeholders.
useClipboardHandlersCopy / cut / paste of elements.
useFindReplaceFind & replace across slide text.
useCommentsComment thread state and CRUD.
useAnnotationHandlersFreehand/shape annotation drawing handlers.

Canvas interaction ​

HookConcern
usePointerHandlersMouse/touch event processing for the canvas.
useCanvasInteractionsSelection box, drag-select, canvas-level gestures.
useZoomViewportZoom level, fit-to-width, viewport DOM ref.
useKeyboardShortcutsHotkey definitions.
useKeyboardShortcutWiringWires hotkey definitions to DOM event listeners.
useResizablePanelsResizable inspector/sidebar panel widths.
useSheetDismissDragSwipe-to-dismiss for bottom sheets (mobile).
useModalDismissDragSwipe-to-dismiss for modals (mobile).

Export, print & I/O ​

HookConcern
useExportHandlersPNG / SVG / PDF / GIF / video / PPTX export logic.
useExportSaveAs"Save as" file-picker flow around export.
usePrintHandlersPrint dialog and layout.
useIOHandlersOpen/import file handling.
useFontInjectionInjects embedded document fonts into the page.
useVirtualizedSlides (+ computeVirtualRange)Virtualizes the slide panel/list for large decks.

Dialogs ​

HookConcern
useViewerDialogsOpen/close state for every modal dialog.
useDialogCustomShowsCustom "show" gating logic for specific dialogs.

Presentation mode ​

HookConcern
usePresentationModeSlideshow navigation, animation, transitions (top-level composer).
usePresentationSetupPresentation-mode entry setup (fullscreen, initial slide).
usePresentationAnnotationsPen/highlighter annotations while presenting.
useAnimationPlaybackPlays back element animation timelines.
useRehearsalTimingsRecords per-slide timings during a rehearsal pass.
usePresentationKeyboardKeyboard navigation while presenting.
useSlideNavigationNext/previous/jump slide navigation.
useZoomNavigationZoom/pan while presenting.
usePresenterWindowPresenter-window <-> audience-window messaging.
useAudienceModeAudience-window-side rendering mode.

Slide-transition helpers ​

The framework-agnostic logic every binding uses lives in ooxml-ui/pptx; the private pptx-viewer-shared package is only its compatibility facade. A host embedding its own presentation stage (a custom SlideStage instead of the full PowerPointViewer) still needs the transition resolver/keyframes, so the whole surface is re-exported here instead:

ExportConcern
resolveSlideTransitionResolve a PptxSlideTransition to CSS animation shorthands for the outgoing/incoming layers.
resolveTransitionDurationMsEffective duration (ms) for a transition, honoring an authored duration, the legacy spd token, and PowerPoint's own defaults.
getSlideTransitionAnimationsLower-level resolver resolveSlideTransition calls internally (classic 2-D transition family).
getCinematicTransitionAnimations / getP14TransitionAnimationsThe Office 2013+ (p15) cinematic family and the Office 2010 (p14) exotic/3-D family, respectively.
SLIDE_TRANSITION_KEYFRAMES (alias SLIDE_TRANSITION_KEYFRAMES_CSS)The full @keyframes block every resolved animation name above references. Inject once via a <style> tag.
CINEMATIC_TRANSITION_KEYFRAMES / P14_TRANSITION_KEYFRAMES_ALLThe keyframe sub-blocks already folded into SLIDE_TRANSITION_KEYFRAMES; exported individually too.
resolveDirection / resolveDirection8 / resolveOrientationNormalize an OOXML dir/orient token to a resolved direction/orientation.
resolveWheelSpokeCountSnap an authored Wheel spoke count to the nearest PowerPoint-offered value.
RANDOM_ELIGIBLE_TYPES, INSTANT, DEFAULT_TRANSITION_DURATION_MS, DEFAULT_MORPH_DURATION_MS, TRANSITION_SPEED_DURATION_MS, EASE, WHEEL_SPOKE_COUNTSSupporting constants used by the resolvers above.
PresentationTransitionOverlay, MorphTransitionOverlay, SlideLayer, FragmentedTransitionLayerThe presentation-mode transition overlay components themselves, for a host that wants the whole rendered overlay rather than just the CSS resolver.

Collaboration ​

See Collaboration for the curated public subset. The full internal set:

HookConcern
useYjsProviderManages the Yjs WebSocket provider lifecycle.
useYjsDocumentSyncSyncs the Yjs document into viewer state.
usePresenceTrackingTracks remote cursors, selection, and connection status.
useCollaborativeStateCRDT-backed shared document state.
useCollaborativeHistoryCollaborative undo/redo.
useBroadcastFollowerFollows another user's viewport/selection broadcast.
useFollowMode"Follow presenter" mode orchestration.

Mobile & responsive ​

HookConcern
useIsMobileDevice/viewport classification (mobile/tablet/orientation).
useTouchGesturesPinch-zoom, pan, and tap-gesture recognition.
useKeyboardInsetsAdjusts layout for the on-screen keyboard (mobile).
useSwipeNavigationSwipe-to-change-slide navigation (mobile).
useReducedMotionRespects prefers-reduced-motion for animations/transitions.

This list is generated from packages/react/src/viewer/hooks/**/*.ts and re-exported in full from pptx-react-viewer/internals. If you add or rename a hook there, update this page in the same change.

useViewerBuildingBlocks: host workflows ​

useViewerBuildingBlocks is exported from the package root (pptx-react-viewer), not only from pptx-react-viewer/internals. Its actions object finishes the picker, dialog and layout workflows that the building blocks do not mount. The prose and examples are on the Hooks page; this section lists the exact shapes.

Options ​

OptionTypeDescription
onRequest(request: BuildingBlockRequest) => voidCalled when a toolbar control or the canvas raises a request the building blocks cannot mount. The request also stays in actions.pending until it is completed or cancelled.
fileLimitsHostFileLimitsCeilings for files from the host's own picker. A larger file returns 'file-too-large'. The defaults are 25 MiB for images and 100 MiB for audio and video.
ts
interface HostFileLimits {
	/** Largest accepted image, in bytes. Defaults to 25 MiB (26214400). */
	imageBytes?: number;
	/** Largest accepted audio or video file, in bytes. Defaults to 100 MiB (104857600). */
	mediaBytes?: number;
}

Requests ​

ts
type BuildingBlockRequest =
	| { kind: 'image' }
	| { kind: 'media' }
	| { kind: 'hyperlink' }
	| { kind: 'smartArt' }
	| { kind: 'chart' }
	| { kind: 'equation'; existingOmml: Record<string, unknown> | null };
kindRaised byFinish withAvailable when
imageThe Picture controlactions.insertImage(file)insertImage
mediaThe Video controlactions.insertMedia(file)insertMedia
hyperlinkThe Link control and its canvas gestureactions.hyperlink.apply(data)hyperlink
smartArtThe SmartArt controlactions.smartArt.insert(layout, items)insertSmartArt
chartThe Chart controlactions.chart.insert(kind, options?)insertChart
equationThe Equation control, or a double-click on an equation. existingOmml is the equation being edited, null for a new oneactions.equation.insert(omml), or actions.equation.update(omml) for an existing oneinsertEquation or editEquation

A request is raised only when its action is available. A successful matching operation clears actions.pending; a failed one leaves it set. actions.cancel() clears it without changing the deck.

Operations ​

Operations return BuildingBlockResult (see Results and failure codes) unless the signature says otherwise.

MemberSignatureAvailability id
pendingBuildingBlockRequest | nullnone
cancel() => voidnone
insertImage(file: File) => Promise<BuildingBlockResult>insertImage
insertMedia(file: File) => Promise<BuildingBlockResult>insertMedia
hyperlink.currentHyperlinkEditData | nullnone (reads the selection)
hyperlink.slideCountnumbernone
hyperlink.apply(data: HyperlinkEditData) => BuildingBlockResulthyperlink
hyperlink.remove() => BuildingBlockResultremoveHyperlink
smartArt.insert(layout: SmartArtLayout, items: string[]) => BuildingBlockResultinsertSmartArt
chart.insert(kind: InsertChartKind, options?: InsertChartOptions) => BuildingBlockResultinsertChart
equation.currentRecord<string, unknown> | nullnone (reads the selection)
equation.insert(omml: Record<string, unknown>) => BuildingBlockResultinsertEquation
equation.update(omml: Record<string, unknown>) => BuildingBlockResulteditEquation
findReplaceBuildingBlockFindReplace (below)replace (replace only)
layoutBuildingBlockLayoutActions (below)applyLayout, resetLayout
availabilityRecord<BuildingBlockActionId, BuildingBlockActionState>none
unmountedDialogActionsreadonly string[]none

hyperlink.slideCount is the number of slides a slide-target picker can link to. hyperlink.current is the selected element's link as editor values. equation.current is the selected element's equation (OMML), or null. insertImage centres the picture on the slide, fitted to it.

unmountedDialogActions lists the toolbarProps handlers whose dialog the building blocks do not mount: onOpenPasswordProtection, onOpenDocumentProperties, onOpenFontEmbedding, onOpenDigitalSignatures, onOpenSetUpSlideShow, onOpenCustomShows, onOpenBroadcastDialog and onToggleShortcuts. Hide them with hiddenActions or render the dialog yourself.

Find and replace ​

actions.findReplace exposes the viewer's find state and operations. Searching works in a view-only viewer; replacing is gated by the replace availability id.

MemberTypeNotes
open, setOpenboolean, (open: boolean) => voidWhether the find bar is open. Ctrl+F and Ctrl+H toggle it. The host renders the bar.
query, setQuerystring, (query: string) => void
replacement, setReplacementstring, (replacement: string) => void
options, setOptionsFindReplaceOptions, (options: Partial<FindReplaceOptions>) => voidmatchCase, includeNotes, includeChartTitles and includeChartData, each a boolean.
matchesreadonly FindResult[]
currentIndexnumberZero-based. -1 when there is no current match.
currentMatchFindResult | null
find() => voidSearches again with the current query and options.
next, previous() => voidShows the match's slide and selects its element.
replaceCurrent, replaceAll() => BuildingBlockResultEdit permission, validation and history apply. 'no-match' when there is nothing to replace.

Layouts ​

actions.layout uses the active slide's master's layouts as the allowed set. The Layout dropdown and Reset in toolbarProps run the same operations.

MemberTypeNotes
currentPptxLayoutOption | undefinedThe layout the active slide records, when the deck lists it.
currentPathstring | undefined
availablePptxLayoutOption[]The layouts the active slide may switch to.
apply(path: string) => Promise<BuildingBlockResult>'unknown-layout' for a path not in available, or when applying fails.
reset() => Promise<BuildingBlockResult>Re-applies the slide's own layout. 'no-layout' when it records none.

Charts ​

ts
type InsertChartKind =
	| 'column'
	| 'bar'
	| 'line'
	| 'pie'
	| 'doughnut'
	| 'area'
	| 'scatter'
	| 'histogram'
	| 'pareto'
	| 'funnel'
	| 'treemap'
	| 'sunburst'
	| 'boxWhisker'
	| 'regionMap';

type InsertChartGrouping = 'clustered' | 'stacked' | 'percentStacked';

interface InsertChartOptions {
	/** Default sample title when undefined; no title when empty. */
	title?: string;
	/** Only for the `column`, `bar`, `line` and `area` kinds. */
	grouping?: InsertChartGrouping;
	/** Defaults to true. */
	hasLegend?: boolean;
	/** Host data in place of the sample data. */
	data?: InsertChartData;
}

interface InsertChartData {
	categories: readonly string[];
	series: ReadonlyArray<{ name: string; values: readonly number[] }>;
}

data needs at least one category and one series, and every series needs one finite value per category. Otherwise chart.insert returns 'invalid-data', after the availability check.

Availability ​

ts
type BuildingBlockActionId =
	| 'insertImage'
	| 'insertMedia'
	| 'hyperlink'
	| 'removeHyperlink'
	| 'insertSmartArt'
	| 'insertChart'
	| 'insertEquation'
	| 'editEquation'
	| 'replace'
	| 'applyLayout'
	| 'resetLayout';

interface BuildingBlockActionState {
	/** The operation would run now. When false, `reason` says why. */
	available: boolean;
	reason?: BuildingBlockFailureCode;
	/** The toolbar control only raises a request; the host must render the picker or dialog. */
	needsHostUi: boolean;
}

Every entry checks the shared conditions first: 'not-ready' (loading or failed), 'read-only' (not in edit mode, or no edit permission) and 'protected' (read-only recommended or Protected View). The action's own conditions follow. The first failing condition is the reason.

IdneedsHostUiOwn conditions, in order
insertImagetrue'no-slide'
insertMediatrue'no-slide'
hyperlinktrue'no-selection'
removeHyperlinkfalse'no-selection', then 'no-hyperlink'
insertSmartArttrue'no-slide'
insertCharttrue'no-slide'
insertEquationtrue'no-slide'
editEquationtrue'no-selection', then 'no-equation'
replacefalsenone
applyLayoutfalse'no-slide', then 'no-layout' (no handler, or no layouts)
resetLayoutfalse'no-slide', then 'no-layout' (no handler, or no recorded layout)

Results and failure codes ​

ts
type BuildingBlockResult = { ok: true } | { ok: false; code: BuildingBlockFailureCode };

Codes are not English text, so render them in your own language. An operation reports its availability reason first, then checks its arguments. A failed operation leaves the deck unchanged.

codeMeaningReturned by
not-readyThe deck is still loading or failed to load.Every operation
read-onlyNot editable: view-only, not in edit mode, or no edit permission.Every operation
protectedRead-only recommended or Protected View, so inserting is blocked.Every operation
no-slideThere is no active slide.insertImage, insertMedia, smartArt.insert, chart.insert, equation.insert, layout.apply, layout.reset
no-selectionNothing is selected.hyperlink.apply, hyperlink.remove, equation.update
no-fileNo file was given.insertImage, insertMedia
empty-fileThe file has no content.insertImage, insertMedia
unsupported-typeNot an image (for insertImage), or not an audio or video type (for insertMedia).insertImage, insertMedia
file-too-largeThe file is larger than fileLimits allows.insertImage, insertMedia
decode-failedThe image or media file could not be read or decoded.insertImage, insertMedia
stale-targetThe deck, the active slide or its position changed while the file was decoded or probed. Nothing was inserted.insertImage, insertMedia
unsafe-urlThe link uses a script-like scheme (javascript:, data:, vbscript: or mhtml:).hyperlink.apply
invalid-targetThe link has neither a URL nor an action.hyperlink.apply
no-hyperlinkThe selected element has no link.hyperlink.remove
no-equationThe selected element has no equation.equation.update
no-matchThere is no current match (replaceCurrent), or no match at all (replaceAll).findReplace.replaceCurrent, findReplace.replaceAll
unknown-layoutThe path is not in layout.available, or applying the layout failed.layout.apply
invalid-dataThe data given to chart.insert does not meet the rules in Charts.chart.insert
no-layoutThe slide records no layout (Reset), or there is no handler or no layouts (apply).layout.apply, layout.reset

Released under the Apache-2.0 License.