Skip to content

Commit

Permalink
Merge pull request #1218 from gitbrent/pr-1133
Browse files Browse the repository at this point in the history
Pr 1133
  • Loading branch information
gitbrent authored Feb 8, 2023
2 parents dd88012 + 910c430 commit fbcda3e
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 6 deletions.
10 changes: 7 additions & 3 deletions demos/modules/demo_table.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* AUTH: Brent Ely (https://github.com/gitbrent/)
* DESC: Common test/demo slides for all library features
* DEPS: Used by various demos (./demos/browser, ./demos/node, etc.)
* VER.: 3.10.0
* BLD.: 20220220
* VER.: 3.12.0
* BLD.: 20230207
*/

import {
Expand Down Expand Up @@ -594,15 +594,19 @@ function genSlide07(pptx) {

// EX-3: "Master Page with Auto-Paging"
{
slide = pptx.addSlide({ sectionTitle: "Tables: Auto-Paging", masterName: "MASTER_PLAIN" });
slide = pptx.addSlide({ sectionTitle: "Tables: Auto-Paging", masterName: "MASTER_AUTO_PAGE_TABLE_PLACEHOLDER" });
slide.addText(
[
{ text: "Table Examples: ", options: DEMO_TITLE_TEXT },
{ text: "Master Page with Auto-Paging", options: DEMO_TITLE_OPTS },
],
{ x: 0.5, y: 0.13, w: "90%" }
);
slide.addText("Auto-Paging table", { placeholder: "footer" });
slide.addTable(arrRows, { x: 1.0, y: 0.6, colW: [0.75, 1.75, 7], margin: 0.05, border: { color: "CFCFCF" }, autoPage: true });
// HOWTO: In cases where you want to add custom text, placeholders, etc. to slidemasters, a reference to these slide(s) is needed
// HOWTO: Use the `newAutoPagedSlides` to access references (see [Issue #625](https://github.com/gitbrent/PptxGenJS/issues/625))
slide.newAutoPagedSlides.forEach((slide) => slide.addText("Auto-Paging table continued...", { placeholder: "footer" }));
}

// EX-4: "Auto-Paging Disabled"
Expand Down
18 changes: 18 additions & 0 deletions demos/modules/masters.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,24 @@ export function createMasterSlides(pptx) {
slideNumber: { x: 0.6, y: 7.1, color: "FFFFFF", fontFace: "Arial", fontSize: 10, align: "center" },
});

// MASTER_AUTO_PAGE_TABLE_PLACEHOLDER
pptx.defineSlideMaster({
title: "MASTER_AUTO_PAGE_TABLE_PLACEHOLDER",
background: { fill: "F1F1F1" },
margin: [0.5, 0.25, 1.0, 0.25],
objects: [
{ rect: { x: 0.0, y: 6.9, w: "100%", h: 0.6, fill: { color: "003b75" } } },
{ image: { x: 11.45, y: 5.95, w: 1.67, h: 0.75, data: STARLABS_LOGO_SM } },
{
placeholder: {
options: { name: "footer", x: 0, y: 6.9, w: "100%", h: 0.6, align: "center", valign: "middle", color: "FFFFFF", fontSize: 12 },
text: "(footer placeholder)",
},
},
],
slideNumber: { x: 0.6, y: 7.1, color: "FFFFFF", fontFace: "Arial", fontSize: 10, align: "center" },
});

// MASTER_SLIDE (MASTER_PLACEHOLDER)
pptx.defineSlideMaster({
title: "MASTER_SLIDE",
Expand Down
9 changes: 8 additions & 1 deletion src/gen-objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,7 @@ export function addTableDefinition (
presLayout: PresLayout,
addSlide: (options?: AddSlideProps) => PresSlide,
getSlide: (slideNumber: number) => PresSlide
): void {
): PresSlide[] {
const slides: PresSlide[] = [target] // Create array of Slides as more may be added by auto-paging
const opt: TableProps = options && typeof options === 'object' ? options : {}
opt.objectName = opt.objectName ? encodeXmlEntities(opt.objectName) : `Table ${target._slideObjects.filter(obj => obj._type === SLIDE_OBJECT_TYPES.table).length}`
Expand Down Expand Up @@ -932,6 +932,9 @@ export function addTableDefinition (
})
})

// If autoPage = true, we need to return references to newly created slides if any
const newAutoPagedSlides: PresSlide[] = []

// STEP 6: Auto-Paging: (via {options} and used internally)
// (used internally by `tableToSlides()` to not engage recursion - we've already paged the table data, just add this one)
if (opt && !opt.autoPage) {
Expand Down Expand Up @@ -966,9 +969,13 @@ export function addTableDefinition (

// Add rows to new slide
newSlide.addTable(slide.rows, Object.assign({}, opt))

// Add reference to the new slide so it can be returned, but don't add the first one because the user already has a reference to that one.
if (idx > 0) newAutoPagedSlides.push(newSlide)
}
})
}
return newAutoPagedSlides
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/pptxgen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ import * as genMedia from './gen-media'
import * as genTable from './gen-tables'
import * as genXml from './gen-xml'

const VERSION = '3.12.0-beta-20230207-2320'
const VERSION = '3.12.0-beta-20230207-2340'

export default class PptxGenJS implements IPresentationProps {
// Property getters/setters
Expand Down
7 changes: 6 additions & 1 deletion src/slide.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export default class Slide {
public _slideNum: number
public _slideNumberProps: SlideNumberProps
public _slideObjects: ISlideObject[]
public _newAutoPagedSlides: PresSlide[]

constructor (params: {
addSlide: (options?: AddSlideProps) => PresSlide
Expand Down Expand Up @@ -152,6 +153,10 @@ export default class Slide {
return this._slideNumberProps
}

public get newAutoPagedSlides(): PresSlide[] {
return this._newAutoPagedSlides
}

/**
* Add chart to Slide
* @param {CHART_NAME|IChartMulti[]} type - chart type
Expand Down Expand Up @@ -223,7 +228,7 @@ export default class Slide {
*/
addTable (tableRows: TableRow[], options?: TableProps): Slide {
// FUTURE: we pass `this` - we dont need to pass layouts - they can be read from this!
genObj.addTableDefinition(this, tableRows, options, this._slideLayout, this._presLayout, this.addSlide, this.getSlide)
this._newAutoPagedSlides = genObj.addTableDefinition(this, tableRows, options, this._slideLayout, this._presLayout, this.addSlide, this.getSlide)
return this
}

Expand Down
4 changes: 4 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2533,6 +2533,10 @@ declare namespace PptxGenJS {
* Slide number options
*/
slideNumber: SlideNumberProps
/**
* New slides added by an auto paged table
*/
newAutoPagedSlides: PresSlide[]
/**
* Add chart to Slide
* @param {CHART_NAME|IChartMulti[]} type - chart type
Expand Down

0 comments on commit fbcda3e

Please sign in to comment.