Files
powerpoint-toolbox/docs/DEVELOPERS.md
T
schihei 89989c04e9
CI / build (push) Canceled after 0s
Modernize platform, structure, and UX
Phase 3:
- Declare PowerPointApi 1.5 and replace template manifest values
- Remove the dead command pipeline and the tracked Babel/polyfill setup
- Extract constants, status/settings contexts, PowerPoint services, and an error boundary
- Build with ES2020 and strict TypeScript; hash production assets and drop prod source maps
- Add Vitest tests, CI, LICENSE, Node 20 pinning, and prune unused dependencies
- Correct the README, user guide, developer guide, and audit notes

Phase 4:
- Add a persisted 16:9/4:3 slide size setting used by all layout tools
- Add dark mode with Office/system theme detection
- Make sections collapsible and move to accessible Fluent controls
- Announce status through aria-live and add semantic status icons
- Add a progress counter with cooperative cancellation and a Stop button
- Update the tracked dependency tree for the pruned packages
2026-11-25 12:01:40 +01:00

11 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.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:

    git clone https://gitea.h3132.de/Edison/powerpoint-toolbox.git
    cd powerpoint-toolbox
    
  2. Install dependencies:

    npm ci
    
  3. Build:

    npm run build:dev
    
  4. 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."
>
  Remove
</ConfirmButton>

Section

Collapsible grouping with consistent styling:

<Section title="My Feature">
  <MyFeatureComponent />
</Section>

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:

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.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 <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.

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