diff --git a/sites/lab/page-templates/workbench.js b/sites/lab/page-templates/workbench.js index 8ee968dc216..cce0452eac7 100644 --- a/sites/lab/page-templates/workbench.js +++ b/sites/lab/page-templates/workbench.js @@ -1,6 +1,6 @@ import Page from 'site/components/wrappers/page.js' import useApp from 'site/hooks/useApp.js' -import WorkbenchWrapper from 'shared/components/wrappers/workbench' +import WorkbenchWrapper from 'shared/components/wrappers/workbench.js' import { useRouter } from 'next/router' import Layout from 'site/components/layouts/lab' diff --git a/sites/shared/components/workbench/exporting/pdf-maker.js b/sites/shared/components/workbench/exporting/pdf-maker.js index 317bd7b8ce9..81469f14052 100644 --- a/sites/shared/components/workbench/exporting/pdf-maker.js +++ b/sites/shared/components/workbench/exporting/pdf-maker.js @@ -46,6 +46,8 @@ export default class PdfMaker { /** the height of the entire svg, in points */ svgHeight + pageCount = 0 + constructor({svg, settings, pages, strings}) { this.settings = settings this.pagesWithContent = pages.withContent; @@ -108,26 +110,28 @@ export default class PdfMaker { /** generate the cover page for the pdf */ async generateCoverPage() { + // don't make one if it's not requested if (!this.settings.coverPage) { return } - await this.generateCoverPageTitle() + const headerLevel = await this.generateCoverPageTitle() //abitrary margin for visual space let coverMargin = 85 - let coverHeight = this.pdf.page.height - coverMargin * 2 + let coverHeight = this.pdf.page.height - coverMargin * 2 - headerLevel let coverWidth = this.pdf.page.width - coverMargin * 2 // add the entire pdf to the page, so that it fills the available space as best it can - await SVGtoPDF(this.pdf, this.svg, coverMargin, coverMargin * 1.5, { + await SVGtoPDF(this.pdf, this.svg, coverMargin, headerLevel + coverMargin, { width: coverWidth, height: coverHeight, assumePt: false, // use aspect ratio to center it preserveAspectRatio: 'xMidYMid meet' }); + this.pageCount++ } async generateCoverPageTitle() { @@ -161,6 +165,8 @@ export default class PdfMaker { this.pdf.fillColor('#888888') this.pdf.fontSize(10) this.pdf.text(this.strings.url, lineStart, lineLevel) + + return lineLevel } /** generate the pages of the pdf */ @@ -185,13 +191,14 @@ export default class PdfMaker { let y = -h * this.pageHeight + startMargin // if there was no cover page, the first page already exists - if (this.settings.coverPage || h+w > 0) { + if (this.pageCount > 0) { // otherwise make a new page this.pdf.addPage() } // add the pdf to the page, offset by the page distances await SVGtoPDF(this.pdf, this.svg, x, y, options) + this.pageCount++; } } } diff --git a/sites/shared/components/wrappers/workbench.js b/sites/shared/components/wrappers/workbench.js index 17c7e48488b..40c9f3876b9 100644 --- a/sites/shared/components/wrappers/workbench.js +++ b/sites/shared/components/wrappers/workbench.js @@ -11,7 +11,7 @@ import Modal from 'shared/components/modal' import Measurements from 'shared/components/workbench/measurements/index.js' import LabDraft from 'shared/components/workbench/draft/index.js' import LabSample from 'shared/components/workbench/sample.js' -import ExportDraft from 'shared/components/workbench/exporting/index' +import ExportDraft from 'shared/components/workbench/exporting/index.js' import GistAsJson from 'shared/components/workbench/json.js' import GistAsYaml from 'shared/components/workbench/yaml.js' import DraftEvents from 'shared/components/workbench/events.js' @@ -113,6 +113,7 @@ const WorkbenchWrapper = ({ app, design, preload=false, from=false, layout=false // Generate the draft here so we can pass it down to both the view and the options menu let draft = false if (['draft', 'events', 'test', 'printingLayout'].indexOf(gist._state?.view) !== -1) { + gist.embed = true // get the appropriate layout for the view const layout = gist.layouts?.[gist._state.view] || gist.layout || true // hand it separately to the design diff --git a/sites/shared/prebuild/lab.mjs b/sites/shared/prebuild/lab.mjs index ebd71b55078..e55a803d485 100644 --- a/sites/shared/prebuild/lab.mjs +++ b/sites/shared/prebuild/lab.mjs @@ -33,7 +33,7 @@ const loadFromUnpkg = (design, version) => { const pageTemplate = design => `${header} import design from 'designs/${design}/src/index.js' import { serverSideTranslations } from 'next-i18next/serverSideTranslations' -import PageTemplate from 'site/page-templates/workbench' +import PageTemplate from 'site/page-templates/workbench.js' const Page = (props) => export default Page