diff --git a/sites/shared/components/workbench/draft/svg-wrapper.js b/sites/shared/components/workbench/draft/svg-wrapper.js index 829bf4bd113..88374691daa 100644 --- a/sites/shared/components/workbench/draft/svg-wrapper.js +++ b/sites/shared/components/workbench/draft/svg-wrapper.js @@ -30,7 +30,6 @@ const SvgWrapper = forwardRef((props, ref) => { const { patternProps = false, gist, updateGist, unsetGist, showInfo, viewBox } = props if (!patternProps) return null - console.log(props.children) return ( diff --git a/sites/shared/components/workbench/layout/draft/index.js b/sites/shared/components/workbench/layout/draft/index.js index 0a82cdb487e..7916ca6e30b 100644 --- a/sites/shared/components/workbench/layout/draft/index.js +++ b/sites/shared/components/workbench/layout/draft/index.js @@ -1,5 +1,5 @@ import { useRef } from 'react' -import Stack from './part' +import Stack from './stack' import SvgWrapper from '../../draft/svg-wrapper' import { PartInner } from '../../draft/part' @@ -60,19 +60,21 @@ const Draft = (props) => { } } - // We need to make sure the `pages` part is at the bottom of the pile - // so we can drag-drop all parts on top of it. - // Bottom in SVG means we need to draw it first const viewBox = layout.topLeft ? `${layout.topLeft.x} ${layout.topLeft.y} ${layout.width} ${layout.height}` : false + // We need to make sure the `pages` part is at the bottom of the pile + // so we can drag-drop all parts on top of it. + // Bottom in SVG means we need to draw it first const stacks = [ , ] + + // then make a stack component for each remaining stack for (var stackName in patternProps.stacks) { if (stackName === props.layoutPart) { continue diff --git a/sites/shared/components/workbench/layout/draft/part.js b/sites/shared/components/workbench/layout/draft/stack.js similarity index 100% rename from sites/shared/components/workbench/layout/draft/part.js rename to sites/shared/components/workbench/layout/draft/stack.js diff --git a/sites/shared/components/workbench/layout/print/plugin.js b/sites/shared/components/workbench/layout/print/plugin.js index 40bd480181f..7a0fdabf8ff 100644 --- a/sites/shared/components/workbench/layout/print/plugin.js +++ b/sites/shared/components/workbench/layout/print/plugin.js @@ -50,6 +50,7 @@ export const pagesPlugin = ({ size = 'a4', ...settings }) => { return basePlugin({ ...settings, sheetWidth, sheetHeight }) } +/** check if there is anything to render on the given section of the svg so that we can skip empty pages */ const doScanForBlanks = (stacks, layout, x, y, w, h) => { let hasContent = false for (var s in stacks) { @@ -113,6 +114,7 @@ const basePlugin = ({ name: partName, draft: (shorthand) => { const layoutData = shorthand.store.get('layoutData') + // only actually draft the part if layout data has been set if (layoutData) { shorthand.macro('addPages', layoutData, shorthand) shorthand.part.unhide() @@ -122,22 +124,29 @@ const basePlugin = ({ return shorthand.part }, }) + + // Re-calculate the pattern's config pattern.getConfig() + // create the part so that a stack gets made for it during packing + // but don't draft it so that it doesn't have a size pattern.createPartForSet(partName, pattern.activeSet) }, postLayout: function (pattern) { let { height, width, stacks } = pattern if (!responsiveColumns) width = sheetWidth + // get the layout const layout = typeof pattern.settings[0].layout === 'object' ? pattern.settings[0].layout : pattern.autoLayout + // if the layout doesn't start at 0,0 we want to account for that in our height and width if (layout?.topLeft) { height += layout.topLeft.y responsiveColumns && (width += layout.topLeft.x) } + // store the layout data so the part can use it during drafting pattern.setStores[pattern.activeSet].set('layoutData', { size: [sheetHeight, sheetWidth], height, @@ -145,16 +154,11 @@ const basePlugin = ({ layout, stacks, }) - // But add the part to the autoLayout property - // pattern.autoLayout.parts[partName] = { - // move: { x: 0, y: 0 } - // } - // TODO migrate this to v3 parts adding - // Add pages - // const { macro } = pattern.config.parts[partName].shorthand() + // draft the part pattern.draftPartForSet(partName, pattern.activeSet) + // if the pattern size is supposed to be re-set to the full width and height of all pages, do that if (setPatternSize) { const generatedPageData = pattern.setStores[pattern.activeSet].get('pages') pattern.width = sheetWidth * generatedPageData.cols diff --git a/sites/shared/components/wrappers/workbench.js b/sites/shared/components/wrappers/workbench.js index 9e74bd913ca..fbffb9ea676 100644 --- a/sites/shared/components/wrappers/workbench.js +++ b/sites/shared/components/wrappers/workbench.js @@ -118,7 +118,6 @@ const WorkbenchWrapper = ({ app, design, preload = false, from = false, layout = const layout = gist.layouts?.[gist._state.view] || gist.layout || true // hand it separately to the design draft = new design({ ...gist, layout }) - console.log({ draft, design, gist }) //draft.__init() // add theme to svg renderer