- Add 12 × 8 and 24 × 16 wireframe presets plus custom columns, rows, gutter, opacity, and colour - Place the raster on the current slide, its layout, or the slide master so background rasters sit behind content - Keep one raster per presentation: add clears every scope and remove cleans the whole presentation - Share the colour swatch control across grids, guidelines, and rasters, including grey - Add raster geometry tests and document scope, background, and export caveats
12 KiB
Edison PowerPoint Add-in Developer Documentation
This document provides technical information for developers working on the Edison PowerPoint Add-in.
Architecture Overview
Edison is a PowerPoint task pane add-in built with:
- TypeScript for type-safe code
- React 18 for UI components
- Office.js (PowerPointApi 1.5) for PowerPoint integration
- Fluent UI v9 for Microsoft-style components
- Webpack 5 with
ts-loader - Vitest for unit tests
The application separates UI, shared state, and PowerPoint operations:
- Components render tools and collect user input.
context/holds shared status/progress state and per-presentation settings.services/contains batched PowerPoint operations and pure helpers.constants.tsis the single source for slide size presets and shape name constants.
UML Diagrams
The diagrams under docs/ predate the context/service refactoring and should be treated as historical overviews. The source tree below is authoritative.
Project Structure
/
├── src/
│ └── taskpane/
│ ├── components/
│ │ ├── App.tsx # Layout, status, settings UI
│ │ ├── ActionButton.tsx # Processing/error-aware button
│ │ ├── ConfirmButton.tsx # Confirmation dialog button
│ │ ├── ErrorBoundary.tsx # Render error fallback
│ │ ├── Section.tsx # Collapsible section
│ │ ├── AlignmentButtons.tsx
│ │ ├── ConfidentialButtons.tsx
│ │ ├── DraftButtons.tsx
│ │ ├── GridGuidelineManager.tsx
│ │ ├── InsertTitles.tsx
│ │ ├── MatchProperties.tsx
│ │ ├── MatchSizes.tsx
│ │ ├── ProgressBarButtons.tsx
│ │ ├── RasterManager.tsx
│ │ ├── RoundImage.tsx
│ │ ├── SwapPositions.tsx
│ │ ├── commonStyles.tsx
│ │ └── ColorSwatches.tsx
│ ├── context/
│ │ ├── SettingsContext.tsx # Slide size preset (persisted)
│ │ └── StatusContext.tsx # Status, processing, progress
│ ├── services/
│ │ ├── cancellation.ts # Cooperative cancellation flag
│ │ ├── markers.ts # Confidential/draft markers
│ │ ├── progressBar.ts # Progress bar add/remove
│ │ ├── raster.ts # Raster geometry + slide/layout/master targets
│ │ └── titles.ts # Title collection + ranking
│ ├── types/
│ │ ├── office-types.ts # Office.js helpers
│ │ └── globals.d.ts # __APP_VERSION__ declaration
│ ├── constants.ts
│ ├── Root.tsx # Theme, settings, error boundary
│ ├── index.tsx # Entry point
│ └── taskpane.html
├── docs/
├── manifest.xml
├── package.json
├── tsconfig.json
├── vitest.config.mts
└── webpack.config.js
Development Environment Setup
Prerequisites
- Node.js 20 LTS (see
.nvmrc) - npm
- Microsoft PowerPoint (desktop or web)
Setup Steps
-
Clone the repository:
git clone https://gitea.h3132.de/Edison/powerpoint-toolbox.git cd powerpoint-toolbox -
Install dependencies:
npm ci -
Build:
npm run build:dev -
Start the development server and sideload:
npm run start
Local Development Certificates
Office add-ins require HTTPS locally. office-addin-dev-certs creates and installs a self-signed certificate. If you see certificate errors, run:
npx office-addin-dev-certs install
Shared State
Status and progress
StatusContext provides status messages, processing state, progress, and the setters used by ActionButton and tool components:
import { useStatusContext } from "../context/StatusContext";
const {
setStatusMessage,
setStatusType,
isProcessing,
setIsProcessing,
progress,
setProgress
} = useStatusContext();
Wrap long operations in PowerPoint.run and report progress at natural boundaries:
setProgress({ current: index + 1, total: slides.length });
Settings
SettingsContext exposes the per-presentation slide size:
import { useSettings } from "../context/SettingsContext";
const { slideSize, slideSizePreset, setSlideSizePreset } = useSettings();
// slideSize.width / slideSize.height
The selection is stored in Office.context.document.settings and survives task pane reloads for that presentation.
Cancellation
Use the cancellation service for operations that can run long:
import {
resetCancellation,
isCancellationRequested
} from "../services/cancellation";
resetCancellation();
for (const slide of slides) {
if (isCancellationRequested()) break;
// queue work
}
ActionButton and the tool components reset the flag when an operation starts. App.tsx shows a Stop button while processing.
Reusable Components
ActionButton
Handles processing state, error reporting, and optional confirmation:
<ActionButton
title="Insert Titles"
icon={<TextBulletListRegular />}
onClick={doWork}
confirmTitle="Replace text box contents?"
confirmMessage="This replaces the text in the selected text box."
confirmLabel="Insert"
/>
ConfirmButton
For raw Fluent buttons that need a confirmation dialog:
<ConfirmButton
title="Remove"
icon={<DismissRegular />}
onConfirm={remove}
confirmTitle="Remove the grid?"
confirmMessage="This removes the grid from the current slide."
confirmLabel="Remove"
>
Remove
</ConfirmButton>
Section
A single disclosure item. Section renders an AccordionItem, so it must be
placed inside the shared Accordion in App.tsx:
<Accordion multiple collapsible defaultOpenItems={["content"]}>
<Section title="My Feature">
<MyFeatureComponent />
</Section>
</Accordion>
Creating a New Tool
- Create a component in
src/taskpane/components/. - Use
useStatusContext()and, if needed,useSettings(). - Put reusable or batch-heavy PowerPoint logic in
src/taskpane/services/. - Add confirmation for destructive actions.
- Add the component to
App.tsxinside aSection. - Add unit tests for pure logic.
- Update the user and developer docs.
Example:
import * as React from "react";
import { Button } from "@fluentui/react-components";
import { useStatusContext } from "../context/StatusContext";
import { getErrorMessage } from "../types/office-types";
import { resetCancellation } from "../services/cancellation";
const MyNewTool: React.FC = () => {
const { setStatusMessage, setStatusType, isProcessing, setIsProcessing } = useStatusContext();
const performAction = async () => {
resetCancellation();
setIsProcessing(true);
try {
await PowerPoint.run(async (context) => {
// Queue batched operations here
await context.sync();
});
setStatusMessage("Operation completed successfully!");
setStatusType("success");
} catch (error: unknown) {
setStatusMessage(`Error: ${getErrorMessage(error)}`);
setStatusType("error");
} finally {
setIsProcessing(false);
}
};
return (
<Button onClick={performAction} disabled={isProcessing}>
My New Tool
</Button>
);
};
export default MyNewTool;
Common PowerPoint Operations
Type-safe utilities (types/office-types.ts)
getErrorMessage(error); // Safe message extraction
isPictureShape(shape); // shape.type === image
isTextCapableShape(shape); // Requires shape.type to be loaded
isNotNullish(value); // Rejects null and undefined
deleteShapesByPrefix(shapes, prefix); // Requires names to be loaded
getFirstSelectedSlide(context);
selectShapesById(slide, ids);
Selecting shapes
const shapes = context.presentation.getSelectedShapes();
shapes.load("items");
await context.sync();
Creating a positioned text box
const textBox = slide.shapes.addTextBox("Label", {
left: 0,
top: 500,
width: 960,
height: 24
});
textBox.name = "MyMarker";
Removing marks
Load shape names, then queue deletes:
for (const shape of shapes.items) {
shape.load("name");
}
await context.sync();
deleteShapesByPrefix(shapes.items, "edison_grid_");
await context.sync();
Build and Deployment
Commands
npm run build # production build
npm run build:dev # development build
npm run lint # ESLint + Prettier
npm run typecheck # tsc --noEmit
npm test # Vitest
npm run validate # manifest validation
Production URL
webpack.config.js replaces https://localhost:3000/ in the manifest with the production URL. Override it with:
ADDIN_PROD_URL=https://example.com/powerpoint/ npm run build
Version
package.json is the source of truth:
__APP_VERSION__is injected by webpack and shown in the task pane footer.manifest.xmluses the four-part version (1.2.0.0); keep it in sync withpackage.json.
Manifest requirements
The manifest declares PowerPointApi 1.5. Update the <Requirements> element if the add-in starts relying on a newer API set.
Testing
Unit tests use Vitest and live next to the code (*.test.ts):
npm test
Test pure functions and helpers directly. Office.js interactions should be kept behind small service functions so they can be mocked or tested through extracted logic (for example pickTitleText and deleteShapesByPrefix).
Continuous integration runs lint, typecheck, tests, build, and manifest validation on every push and pull request.
UI Guidelines
The pane follows Fluent 2 and Microsoft's Office Add-in UX guidance. The full
rules and review checklist live in docs/UI_GUIDELINES.md.
Key points:
- Use Fluent tokens for colour, spacing, type, radius, and motion. No literal hex values in UI styles (slide colours are the exception).
- Keep one scroll container. Sections must not set
maxHeightoroverflow. - All action buttons use the blue primary style; destructive actions are confirmed by a dialog.
- Labels are verb + object, with a short hint when a selection is required.
- Keep the single always-mounted
role="status"region for feedback.
Performance Guidelines
- Batch
context.sync()calls. Load all needed properties, then sync once. - Avoid per-shape or per-slide syncs. The batch services load items/names in two batches.
- Prefer two shapes over N shapes. The progress bar uses one pending and one completed rectangle per slide.
- Check cancellation between batches. Office.js cannot abort a queued batch.
- Report progress at item boundaries so the user sees activity during long loops.
Best Practices
- Use
getErrorMessageand typecatchvalues asunknown. - Keep
strictTypeScript passing. - Use
useSettings()rather than hardcoded slide dimensions. - Add confirmations for destructive operations.
- Make repeated add operations idempotent.
- Use Fluent
Field/Input/Dropdowncontrols so labels and keyboard navigation work. - Use design tokens and follow
docs/UI_GUIDELINES.mdfor any new UI. - Announce results through the status region (
role="status"). - Update docs when behavior changes.