Skip to content

Commit 75101a1

Browse files
[PowerPoint] Add types (OfficeDev#934)
1 parent 32ac5d6 commit 75101a1

File tree

17 files changed

+407
-198
lines changed

17 files changed

+407
-198
lines changed

playlists-prod/powerpoint.yaml

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
- id: powerpoint-basics-basic-api-call-ts
22
name: Basic API call (TypeScript)
33
fileName: basic-api-call-ts.yaml
4-
description: Performs a basic PowerPoint API call using TypeScript
4+
description: Performs a basic PowerPoint API call using TypeScript.
55
rawUrl: >-
66
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/basics/basic-api-call-ts.yaml
77
group: Basics
8-
api_set: PowerPointApi '1.4'
8+
api_set:
9+
PowerPointApi: '1.4'
910
- id: powerpoint-basics-basic-api-call-js
1011
name: Basic API call (JavaScript)
1112
fileName: basic-api-call-js.yaml
12-
description: Performs a basic PowerPoint API call using JavaScript
13+
description: Performs a basic PowerPoint API call using JavaScript.
1314
rawUrl: >-
1415
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/basics/basic-api-call-js.yaml
1516
group: Basics
16-
api_set: PowerPointApi '1.4'
17+
api_set:
18+
PowerPointApi: '1.4'
1719
- id: powerpoint-basics-basic-common-api-call
1820
name: Basic API call (Office 2013)
1921
fileName: basic-common-api-call.yaml
@@ -24,7 +26,7 @@
2426
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/basics/basic-common-api-call.yaml
2527
group: Basics
2628
api_set:
27-
Selection: 1.1
29+
Selection: '1.1'
2830
- id: powerpoint-create-presentation
2931
name: Create presentation
3032
fileName: create-presentation.yaml
@@ -35,7 +37,7 @@
3537
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/document/create-presentation.yaml
3638
group: Document
3739
api_set:
38-
PowerPoint: 1.1
40+
PowerPoint: '1.1'
3941
- id: powerpoint-basics-insert-image
4042
name: Insert Image
4143
fileName: insert-image.yaml
@@ -85,7 +87,8 @@
8587
rawUrl: >-
8688
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/shapes/shapes.yaml
8789
group: Shapes
88-
api_set: PowerPointApi '1.4'
90+
api_set:
91+
PowerPointApi: '1.4'
8992
- id: powerpoint-add-slides
9093
name: Add slides to a presentation
9194
fileName: add-slides.yaml
@@ -107,7 +110,7 @@
107110
- id: powerpoint-basics-get-slide-metadata
108111
name: Get slide metadata
109112
fileName: get-slide-metadata.yaml
110-
description: 'Gets the title, index, and ID of the selected slide(s).'
113+
description: 'Gets the title, index, and ID of the selected slides.'
111114
rawUrl: >-
112115
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/slide-management/get-slide-metadata.yaml
113116
group: Slide Management

playlists/powerpoint.yaml

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
- id: powerpoint-basics-basic-api-call-ts
22
name: Basic API call (TypeScript)
33
fileName: basic-api-call-ts.yaml
4-
description: Performs a basic PowerPoint API call using TypeScript
4+
description: Performs a basic PowerPoint API call using TypeScript.
55
rawUrl: >-
66
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/main/samples/powerpoint/basics/basic-api-call-ts.yaml
77
group: Basics
8-
api_set: PowerPointApi '1.4'
8+
api_set:
9+
PowerPointApi: '1.4'
910
- id: powerpoint-basics-basic-api-call-js
1011
name: Basic API call (JavaScript)
1112
fileName: basic-api-call-js.yaml
12-
description: Performs a basic PowerPoint API call using JavaScript
13+
description: Performs a basic PowerPoint API call using JavaScript.
1314
rawUrl: >-
1415
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/main/samples/powerpoint/basics/basic-api-call-js.yaml
1516
group: Basics
16-
api_set: PowerPointApi '1.4'
17+
api_set:
18+
PowerPointApi: '1.4'
1719
- id: powerpoint-basics-basic-common-api-call
1820
name: Basic API call (Office 2013)
1921
fileName: basic-common-api-call.yaml
@@ -24,7 +26,7 @@
2426
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/main/samples/powerpoint/basics/basic-common-api-call.yaml
2527
group: Basics
2628
api_set:
27-
Selection: 1.1
29+
Selection: '1.1'
2830
- id: powerpoint-create-presentation
2931
name: Create presentation
3032
fileName: create-presentation.yaml
@@ -35,7 +37,7 @@
3537
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/main/samples/powerpoint/document/create-presentation.yaml
3638
group: Document
3739
api_set:
38-
PowerPoint: 1.1
40+
PowerPoint: '1.1'
3941
- id: powerpoint-basics-insert-image
4042
name: Insert Image
4143
fileName: insert-image.yaml
@@ -85,7 +87,8 @@
8587
rawUrl: >-
8688
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/main/samples/powerpoint/shapes/shapes.yaml
8789
group: Shapes
88-
api_set: PowerPointApi '1.4'
90+
api_set:
91+
PowerPointApi: '1.4'
8992
- id: powerpoint-add-slides
9093
name: Add slides to a presentation
9194
fileName: add-slides.yaml
@@ -107,7 +110,7 @@
107110
- id: powerpoint-basics-get-slide-metadata
108111
name: Get slide metadata
109112
fileName: get-slide-metadata.yaml
110-
description: 'Gets the title, index, and ID of the selected slide(s).'
113+
description: 'Gets the title, index, and ID of the selected slides.'
111114
rawUrl: >-
112115
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/main/samples/powerpoint/slide-management/get-slide-metadata.yaml
113116
group: Slide Management

samples/powerpoint/basics/basic-api-call-js.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
order: 2
22
id: powerpoint-basics-basic-api-call-js
33
name: Basic API call (JavaScript)
4-
description: Performs a basic PowerPoint API call using JavaScript
4+
description: Performs a basic PowerPoint API call using JavaScript.
55
host: POWERPOINT
6-
api_set: PowerPointApi '1.4'
6+
api_set:
7+
PowerPointApi: '1.4'
78
script:
89
content: |
910
$("#run").on("click", () => tryCatch(run));

samples/powerpoint/basics/basic-api-call-ts.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
order: 1
22
id: powerpoint-basics-basic-api-call-ts
33
name: Basic API call (TypeScript)
4-
description: Performs a basic PowerPoint API call using TypeScript
4+
description: Performs a basic PowerPoint API call using TypeScript.
55
host: POWERPOINT
6-
api_set: PowerPointApi '1.4'
6+
api_set:
7+
PowerPointApi: '1.4'
78
script:
89
content: |
910
$("#run").on("click", () => tryCatch(run));

samples/powerpoint/basics/basic-common-api-call.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: Executes a basic PowerPoint API call using the "common API" syntax
55
author: OfficeDev
66
host: POWERPOINT
77
api_set:
8-
Selection: 1.1
8+
Selection: '1.1'
99
script:
1010
content: |
1111
$("#run").on("click", run);

samples/powerpoint/document/create-presentation.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: 'Creates a new, empty presentation and creates a new presentation b
44
author: OfficeDev
55
host: POWERPOINT
66
api_set:
7-
PowerPoint: 1.1
7+
PowerPoint: '1.1'
88
script:
99
content: |
1010
$("#create-new-blank-presentation").on("click", () => tryCatch(createBlankPresentation));

samples/powerpoint/shapes/get-set-shapes.yaml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ script:
1919
// Gets the shapes you selected on the slide and displays their IDs on the task pane.
2020
await PowerPoint.run(async (context) => {
2121
let finalTable = "";
22-
const shapes = context.presentation.getSelectedShapes();
22+
const shapes: PowerPoint.ShapeScopedCollection = context.presentation.getSelectedShapes();
2323
const shapeCount = shapes.getCount();
2424
await context.sync();
2525
finalTable += "<br>getSelectedShapes.getCount returned:<b>" + shapeCount.value + "</b><br>";
@@ -44,9 +44,9 @@ script:
4444
const slide1 = context.presentation.slides.getItemAt(0);
4545
slide1.load("shapes");
4646
await context.sync();
47-
const shapes = slide1.shapes;
48-
const shape1 = shapes.getItemAt(0);
49-
const shape2 = shapes.getItemAt(1);
47+
const shapes: PowerPoint.ShapeCollection = slide1.shapes;
48+
const shape1: PowerPoint.Shape = shapes.getItemAt(0);
49+
const shape2: PowerPoint.Shape = shapes.getItemAt(1);
5050
shape1.load("id");
5151
shape2.load("id");
5252
await context.sync();
@@ -58,7 +58,7 @@ script:
5858
async function changeFill() {
5959
// Changes the selected shapes fill color to red.
6060
await PowerPoint.run(async (context) => {
61-
const shapes = context.presentation.getSelectedShapes();
61+
const shapes: PowerPoint.ShapeScopedCollection = context.presentation.getSelectedShapes();
6262
const shapeCount = shapes.getCount();
6363
shapes.load("items");
6464
await context.sync();
@@ -76,15 +76,15 @@ script:
7676
await PowerPoint.run(async (context) => {
7777
context.presentation.load("slides");
7878
await context.sync();
79-
const slides = context.presentation.getSelectedSlides();
79+
const slides: PowerPoint.SlideScopedCollection = context.presentation.getSelectedSlides();
8080
const slideCount = slides.getCount();
8181
slides.load("items");
8282
await context.sync();
8383
savedSlideSelection = [];
8484
slides.items.map((slide) => {
8585
savedSlideSelection.push(slide.id);
8686
});
87-
const shapes = context.presentation.getSelectedShapes();
87+
const shapes: PowerPoint.ShapeScopedCollection = context.presentation.getSelectedShapes();
8888
const shapeCount = shapes.getCount();
8989
shapes.load("items");
9090
await context.sync();
@@ -97,7 +97,7 @@ script:
9797
async function loadShapeSelection() {
9898
// Reselects shapes that were saved previously.
9999
await PowerPoint.run(async (context) => {
100-
const slide1 = context.presentation.slides.getItem(savedSlideSelection[0]);
100+
const slide1: PowerPoint.Slide = context.presentation.slides.getItem(savedSlideSelection[0]);
101101
await context.sync();
102102
slide1.setSelectedShapes(savedShapeSelection);
103103
await context.sync();
@@ -120,13 +120,13 @@ script:
120120
// Creates random shapes on the selected slide.
121121
await PowerPoint.run(async (context) => {
122122
let finalTable = "";
123-
const currentSlide = context.presentation.getSelectedSlides().getItemAt(0);
123+
const currentSlide: PowerPoint.Slide = context.presentation.getSelectedSlides().getItemAt(0);
124124
const maxNewShapeWidth = 200;
125125
const maxNewShapeHeight = 200;
126126
const minNewShapeWidth = 50;
127127
const minNewShapeHeight = 50;
128128
for (let i = 0; i < 20; i++) {
129-
const rectangle = currentSlide.shapes.addGeometricShape(PowerPoint.GeometricShapeType.rectangle);
129+
const rectangle: PowerPoint.Shape = currentSlide.shapes.addGeometricShape(PowerPoint.GeometricShapeType.rectangle);
130130
rectangle.height = getRandomBetween(minNewShapeWidth, maxNewShapeWidth);
131131
rectangle.width = getRandomBetween(minNewShapeHeight, maxNewShapeHeight);
132132
rectangle.left = getRandomBetween(0, slideWidth - rectangle.width);
@@ -144,7 +144,7 @@ script:
144144
async function arrangeSelected() {
145145
// Arranges the selected shapes in a line from left to right.
146146
await PowerPoint.run(async (context) => {
147-
const shapes = context.presentation.getSelectedShapes();
147+
const shapes: PowerPoint.ShapeScopedCollection = context.presentation.getSelectedShapes();
148148
const shapeCount = shapes.getCount();
149149
shapes.load("items");
150150
await context.sync();

samples/powerpoint/shapes/get-shapes-by-type.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ script:
1515
// Changes the dash style of every line in the slide.
1616
await PowerPoint.run(async (context) => {
1717
// Get the type of shape for every shape in the collection.
18-
const shapes = context.presentation.slides.getItemAt(0).shapes;
18+
const shapes: PowerPoint.ShapeCollection = context.presentation.slides.getItemAt(0).shapes;
1919
shapes.load("type");
2020
await context.sync();
2121
@@ -33,7 +33,7 @@ script:
3333
// Changes the transparency of every geometric shape in the slide.
3434
await PowerPoint.run(async (context) => {
3535
// Get the type of shape for every shape in the collection.
36-
const shapes = context.presentation.slides.getItemAt(0).shapes;
36+
const shapes: PowerPoint.ShapeCollection = context.presentation.slides.getItemAt(0).shapes;
3737
shapes.load("type");
3838
await context.sync();
3939

samples/powerpoint/shapes/shapes.yaml

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ id: powerpoint-shapes
22
name: 'Insert shape, line, and text box'
33
description: 'Inserts geometric shapes, lines, and text boxes to a slide.'
44
host: POWERPOINT
5-
api_set: PowerPointApi '1.4'
5+
api_set:
6+
PowerPointApi: '1.4'
67
script:
78
content: |
89
$("#create-hexagon").on("click", () => tryCatch(createHexagon));
@@ -18,14 +19,14 @@ script:
1819
// and adds a hexagon shape to the collection, while specifying its
1920
// location and size. Then it names the shape.
2021
await PowerPoint.run(async (context) => {
21-
const shapes = context.presentation.slides.getItemAt(0).shapes;
22-
const hexagon = shapes.addGeometricShape(PowerPoint.GeometricShapeType.hexagon,
23-
{
24-
left: 100,
25-
top: 100,
26-
height: 150,
27-
width: 150
28-
});
22+
const shapes: PowerPoint.ShapeCollection = context.presentation.slides.getItemAt(0).shapes;
23+
const shapeOptions: PowerPoint.ShapeAddOptions = {
24+
left: 100,
25+
top: 100,
26+
height: 150,
27+
width: 150
28+
};
29+
const hexagon: PowerPoint.Shape = shapes.addGeometricShape(PowerPoint.GeometricShapeType.hexagon, shapeOptions);
2930
hexagon.name = "Hexagon";
3031
3132
await context.sync();
@@ -36,8 +37,8 @@ script:
3637
// This function gets the collection of shapes on the first slide,
3738
// gets the first shape in the collection, and resets its size.
3839
await PowerPoint.run(async (context) => {
39-
const shapes = context.presentation.slides.getItemAt(0).shapes;
40-
const hexagon = shapes.getItemAt(0);
40+
const shapes: PowerPoint.ShapeCollection = context.presentation.slides.getItemAt(0).shapes;
41+
const hexagon: PowerPoint.Shape = shapes.getItemAt(0);
4142
hexagon.height = 50;
4243
hexagon.width = 50;
4344
@@ -49,8 +50,8 @@ script:
4950
// This function gets the collection of shapes on the first slide,
5051
// gets the first shape in the collection, and resets its location.
5152
await PowerPoint.run(async (context) => {
52-
const shapes = context.presentation.slides.getItemAt(0).shapes;
53-
const hexagon = shapes.getItemAt(0);
53+
const shapes: PowerPoint.ShapeCollection = context.presentation.slides.getItemAt(0).shapes;
54+
const hexagon: PowerPoint.Shape = shapes.getItemAt(0);
5455
hexagon.top = 50;
5556
hexagon.left = 150;
5657
@@ -63,11 +64,11 @@ script:
6364
// and adds a line to the collection, while specifying its
6465
// start and end points. Then it names the shape.
6566
await PowerPoint.run(async (context) => {
66-
const shapes = context.presentation.slides.getItemAt(0).shapes;
67+
const shapes: PowerPoint.ShapeCollection = context.presentation.slides.getItemAt(0).shapes;
6768
6869
// For a line, left and top are the coordinates of the start point,
6970
// while height and width are the coordinates of the end point.
70-
const line = shapes.addLine(PowerPoint.ConnectorType.straight,
71+
const line: PowerPoint.Shape = shapes.addLine(PowerPoint.ConnectorType.straight,
7172
{
7273
left: 400,
7374
top: 200,
@@ -85,8 +86,8 @@ script:
8586
// and adds a text box to the collection, while specifying its text,
8687
// location, and size. Then it names the text box.
8788
await PowerPoint.run(async (context) => {
88-
const shapes = context.presentation.slides.getItemAt(0).shapes;
89-
const textbox = shapes.addTextBox("Hello!",
89+
const shapes: PowerPoint.ShapeCollection = context.presentation.slides.getItemAt(0).shapes;
90+
const textbox: PowerPoint.Shape = shapes.addTextBox("Hello!",
9091
{
9192
left: 100,
9293
top: 300,
@@ -105,8 +106,8 @@ script:
105106
// location and size. Then it names the shape, sets its text and font
106107
// color, and centers it inside the braces.
107108
await PowerPoint.run(async (context) => {
108-
const shapes = context.presentation.slides.getItemAt(0).shapes;
109-
const braces = shapes.addGeometricShape(PowerPoint.GeometricShapeType.bracePair, {
109+
const shapes: PowerPoint.ShapeCollection = context.presentation.slides.getItemAt(0).shapes;
110+
const braces: PowerPoint.Shape = shapes.addGeometricShape(PowerPoint.GeometricShapeType.bracePair, {
110111
left: 100,
111112
top: 400,
112113
height: 50,
@@ -125,8 +126,8 @@ script:
125126
// This function gets the collection of shapes on the first slide,
126127
// and then iterates through them, deleting each one.
127128
await PowerPoint.run(async (context) => {
128-
const slide = context.presentation.slides.getItemAt(0);
129-
const shapes = slide.shapes;
129+
const slide: PowerPoint.Slide = context.presentation.slides.getItemAt(0);
130+
const shapes: PowerPoint.ShapeCollection = slide.shapes;
130131
131132
// Load all the shapes in the collection without loading their properties.
132133
shapes.load("items/$none");

samples/powerpoint/slide-management/add-slides.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ script:
2828
async function logSlideMasters() {
2929
await PowerPoint.run(async function(context) {
3030
// Load information about all the slide masters and associated layouts.
31-
const slideMasters = context.presentation.slideMasters.load("id, name, layouts/items/name, layouts/items/id");
31+
const slideMasters: PowerPoint.SlideMasterCollection = context.presentation.slideMasters.load("id, name, layouts/items/name, layouts/items/id");
3232
await context.sync();
3333
3434
// Log the name and ID of each slide master.
@@ -37,7 +37,7 @@ script:
3737
console.log("Master ID: " + slideMasters.items[i].id);
3838
3939
// Log the name and ID of each slide layout in the slide master.
40-
const layoutsInMaster = slideMasters.items[i].layouts;
40+
const layoutsInMaster: PowerPoint.SlideLayoutCollection = slideMasters.items[i].layouts;
4141
for (let j = 0; j < layoutsInMaster.items.length; j++) {
4242
console.log(" Layout name: " + layoutsInMaster.items[j].name + " Layout ID: " + layoutsInMaster.items[j].id);
4343
}

0 commit comments

Comments
 (0)