# 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.ts` is 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
│ │ ├── RoundImage.tsx
│ │ ├── SwapPositions.tsx
│ │ └── commonStyles.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
│ │ └── 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
1. Clone the repository:
```bash
git clone https://gitea.h3132.de/Edison/powerpoint-toolbox.git
cd powerpoint-toolbox
```
2. Install dependencies:
```bash
npm ci
```
3. Build:
```bash
npm run build:dev
```
4. Start the development server and sideload:
```bash
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:
```bash
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:
```typescript
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:
```typescript
setProgress({ current: index + 1, total: slides.length });
```
### Settings
`SettingsContext` exposes the per-presentation slide size:
```typescript
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:
```typescript
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:
```tsx
}
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:
```tsx
}
onConfirm={remove}
confirmTitle="Remove the grid?"
confirmMessage="This removes the grid from the current slide."
>
Remove
```
### Section
Collapsible grouping with consistent styling:
```tsx
```
## Creating a New Tool
1. Create a component in `src/taskpane/components/`.
2. Use `useStatusContext()` and, if needed, `useSettings()`.
3. Put reusable or batch-heavy PowerPoint logic in `src/taskpane/services/`.
4. Add confirmation for destructive actions.
5. Add the component to `App.tsx` inside a `Section`.
6. Add unit tests for pure logic.
7. Update the user and developer docs.
Example:
```tsx
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 (
);
};
export default MyNewTool;
```
## Common PowerPoint Operations
### Type-safe utilities (`types/office-types.ts`)
```typescript
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
```typescript
const shapes = context.presentation.getSelectedShapes();
shapes.load("items");
await context.sync();
```
### Creating a positioned text box
```typescript
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:
```typescript
for (const shape of shapes.items) {
shape.load("name");
}
await context.sync();
deleteShapesByPrefix(shapes.items, "edison_grid_");
await context.sync();
```
## Build and Deployment
### Commands
```bash
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:
```bash
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.xml` uses the four-part version (`1.2.0.0`); keep it in sync with `package.json`.
### Manifest requirements
The manifest declares `PowerPointApi` 1.5. Update the `` 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`):
```bash
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.
## 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
1. Use `getErrorMessage` and type `catch` values as `unknown`.
2. Keep `strict` TypeScript passing.
3. Use `useSettings()` rather than hardcoded slide dimensions.
4. Add confirmations for destructive operations.
5. Make repeated add operations idempotent.
6. Use Fluent `Field`/`Input`/`Dropdown` controls so labels and keyboard navigation work.
7. Announce results through the status region (`role="status"`).
8. Update docs when behavior changes.
## Resources
- [Office Add-ins documentation](https://learn.microsoft.com/office/dev/add-ins/)
- [Office.js API reference](https://learn.microsoft.com/javascript/api/overview/office)
- [Fluent UI React v9](https://react.fluentui.dev/)
- [Vitest](https://vitest.dev/)