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
This commit is contained in:
1 parent
e57258afe9
commit
89989c04e9
6211 files changed
+7028
-274819
No files matched your search
@@ -14,17 +14,18 @@ import {
|
||||
Edit24Regular,
|
||||
DismissRegular
|
||||
} from "@fluentui/react-icons";
|
||||
import { useStatusContext } from "./App";
|
||||
import { useStatusContext } from "../context/StatusContext";
|
||||
import { useCommonStyles } from "./commonStyles";
|
||||
import { getErrorMessage } from "../types/office-types";
|
||||
import { MARKER_NAMES } from "../constants";
|
||||
import { addMarkerToCollections, removeMarkerFromCollections } from "../services/markers";
|
||||
import { isCancellationRequested, resetCancellation } from "../services/cancellation";
|
||||
import ConfirmButton from "./ConfirmButton";
|
||||
|
||||
/**
|
||||
* Configuration constants for draft watermarks
|
||||
*/
|
||||
const DRAFT_CONFIG = {
|
||||
// Shape name used to identify draft watermarks
|
||||
SHAPE_NAME: "DraftWatermark",
|
||||
// Font configuration
|
||||
FONT: {
|
||||
NAME: "Inter",
|
||||
@@ -94,7 +95,8 @@ export const DraftButtons: React.FC = () => {
|
||||
setStatusMessage,
|
||||
setStatusType,
|
||||
isProcessing,
|
||||
setIsProcessing
|
||||
setIsProcessing,
|
||||
setProgress
|
||||
} = useStatusContext();
|
||||
|
||||
/**
|
||||
@@ -143,6 +145,8 @@ export const DraftButtons: React.FC = () => {
|
||||
* Adds draft watermarks to all master slides in the presentation
|
||||
*/
|
||||
const addDraftWatermark = async (): Promise<void> => {
|
||||
resetCancellation();
|
||||
setProgress(null);
|
||||
setIsProcessing(true);
|
||||
try {
|
||||
await PowerPoint.run(async (context) => {
|
||||
@@ -158,12 +162,18 @@ export const DraftButtons: React.FC = () => {
|
||||
}
|
||||
|
||||
const result = await processAddWatermarks(context, masters.items);
|
||||
if (isCancellationRequested()) {
|
||||
setStatusMessage("Operation cancelled.");
|
||||
setStatusType("warning");
|
||||
return;
|
||||
}
|
||||
updateStatusFromResult(result, true);
|
||||
});
|
||||
} catch (error) {
|
||||
} catch (error: unknown) {
|
||||
handleError(error, "Add draft watermark");
|
||||
} finally {
|
||||
setIsProcessing(false);
|
||||
setProgress(null);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -178,64 +188,39 @@ export const DraftButtons: React.FC = () => {
|
||||
context: PowerPoint.RequestContext,
|
||||
masters: PowerPoint.SlideMaster[]
|
||||
): Promise<ProcessingResult> => {
|
||||
const result: ProcessingResult = {
|
||||
processedMasters: 0,
|
||||
errorMasters: 0,
|
||||
affectedCount: 0
|
||||
};
|
||||
|
||||
const { LEFT, TOP, WIDTH, HEIGHT } = DRAFT_CONFIG.TEXT_BOX;
|
||||
|
||||
// Load the shapes and names for every master in two batches instead of three syncs per master
|
||||
for (const master of masters) {
|
||||
master.shapes.load("items");
|
||||
}
|
||||
await context.sync();
|
||||
const result = await addMarkerToCollections(
|
||||
context,
|
||||
masters.map((master) => master.shapes),
|
||||
{
|
||||
name: MARKER_NAMES.draft,
|
||||
text: DRAFT_CONFIG.TEXT,
|
||||
font: {
|
||||
name: DRAFT_CONFIG.FONT.NAME,
|
||||
size: DRAFT_CONFIG.FONT.SIZE,
|
||||
color: DRAFT_CONFIG.FONT.COLOR,
|
||||
bold: true
|
||||
},
|
||||
box: { left: LEFT, top: TOP, width: WIDTH, height: HEIGHT },
|
||||
verticalAlignment: PowerPoint.TextVerticalAlignment.middleCentered
|
||||
},
|
||||
(current, total) => setProgress({ current, total })
|
||||
);
|
||||
|
||||
const shapesByMaster: PowerPoint.Shape[][] = [];
|
||||
for (const master of masters) {
|
||||
shapesByMaster.push(master.shapes.items);
|
||||
for (const shape of master.shapes.items) {
|
||||
shape.load("name");
|
||||
}
|
||||
}
|
||||
await context.sync();
|
||||
|
||||
// Replace any existing watermark so repeated clicks do not duplicate it
|
||||
for (const shapes of shapesByMaster) {
|
||||
for (const shape of shapes) {
|
||||
if (shape.name === DRAFT_CONFIG.SHAPE_NAME) {
|
||||
shape.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Create one watermark per master in a single batch
|
||||
for (const master of masters) {
|
||||
const textBox = master.shapes.addTextBox(DRAFT_CONFIG.TEXT, {
|
||||
left: LEFT,
|
||||
top: TOP,
|
||||
width: WIDTH,
|
||||
height: HEIGHT
|
||||
});
|
||||
textBox.name = DRAFT_CONFIG.SHAPE_NAME;
|
||||
textBox.textFrame.textRange.font.name = DRAFT_CONFIG.FONT.NAME;
|
||||
textBox.textFrame.textRange.font.size = DRAFT_CONFIG.FONT.SIZE;
|
||||
textBox.textFrame.textRange.font.bold = true;
|
||||
textBox.textFrame.textRange.font.color = DRAFT_CONFIG.FONT.COLOR;
|
||||
textBox.textFrame.verticalAlignment = "MiddleCentered";
|
||||
result.processedMasters++;
|
||||
}
|
||||
|
||||
await context.sync();
|
||||
result.affectedCount = masters.length;
|
||||
return result;
|
||||
return {
|
||||
processedMasters: masters.length,
|
||||
errorMasters: 0,
|
||||
affectedCount: result.affected
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Removes draft watermarks from all master slides in the presentation
|
||||
*/
|
||||
const removeDraftWatermark = async (): Promise<void> => {
|
||||
resetCancellation();
|
||||
setProgress(null);
|
||||
setIsProcessing(true);
|
||||
try {
|
||||
await PowerPoint.run(async (context) => {
|
||||
@@ -251,12 +236,18 @@ export const DraftButtons: React.FC = () => {
|
||||
}
|
||||
|
||||
const result = await processRemoveWatermarks(context, masters.items);
|
||||
if (isCancellationRequested()) {
|
||||
setStatusMessage("Operation cancelled.");
|
||||
setStatusType("warning");
|
||||
return;
|
||||
}
|
||||
updateStatusFromResult(result, false);
|
||||
});
|
||||
} catch (error) {
|
||||
} catch (error: unknown) {
|
||||
handleError(error, "Remove draft watermark");
|
||||
} finally {
|
||||
setIsProcessing(false);
|
||||
setProgress(null);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -271,38 +262,17 @@ export const DraftButtons: React.FC = () => {
|
||||
context: PowerPoint.RequestContext,
|
||||
masters: PowerPoint.SlideMaster[]
|
||||
): Promise<ProcessingResult> => {
|
||||
const result: ProcessingResult = {
|
||||
processedMasters: 0,
|
||||
const result = await removeMarkerFromCollections(
|
||||
context,
|
||||
masters.map((master) => master.shapes),
|
||||
MARKER_NAMES.draft
|
||||
);
|
||||
|
||||
return {
|
||||
processedMasters: masters.length,
|
||||
errorMasters: 0,
|
||||
affectedCount: 0
|
||||
affectedCount: result.affected
|
||||
};
|
||||
|
||||
// Load the shapes and names for every master in two batches
|
||||
for (const master of masters) {
|
||||
master.shapes.load("items");
|
||||
}
|
||||
await context.sync();
|
||||
|
||||
const allShapes: PowerPoint.Shape[] = [];
|
||||
for (const master of masters) {
|
||||
for (const shape of master.shapes.items) {
|
||||
shape.load("name");
|
||||
allShapes.push(shape);
|
||||
}
|
||||
}
|
||||
await context.sync();
|
||||
|
||||
// Delete all matching shapes in one batch
|
||||
for (const shape of allShapes) {
|
||||
if (shape.name === DRAFT_CONFIG.SHAPE_NAME) {
|
||||
shape.delete();
|
||||
result.affectedCount++;
|
||||
}
|
||||
}
|
||||
|
||||
await context.sync();
|
||||
result.processedMasters = masters.length;
|
||||
return result;
|
||||
};
|
||||
|
||||
return (
|
||||
|
||||
Reference in new issue
Block a user