1
0
Fork 0

some comments and cleanup

This commit is contained in:
Enoch Riese 2022-12-12 10:14:28 -06:00
parent d78b2bb6c1
commit 22c92b10d8
5 changed files with 17 additions and 13 deletions

View file

@ -30,7 +30,6 @@ const SvgWrapper = forwardRef((props, ref) => {
const { patternProps = false, gist, updateGist, unsetGist, showInfo, viewBox } = props const { patternProps = false, gist, updateGist, unsetGist, showInfo, viewBox } = props
if (!patternProps) return null if (!patternProps) return null
console.log(props.children)
return ( return (
<SizeMe> <SizeMe>

View file

@ -1,5 +1,5 @@
import { useRef } from 'react' import { useRef } from 'react'
import Stack from './part' import Stack from './stack'
import SvgWrapper from '../../draft/svg-wrapper' import SvgWrapper from '../../draft/svg-wrapper'
import { PartInner } from '../../draft/part' 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 const viewBox = layout.topLeft
? `${layout.topLeft.x} ${layout.topLeft.y} ${layout.width} ${layout.height}` ? `${layout.topLeft.x} ${layout.topLeft.y} ${layout.width} ${layout.height}`
: false : 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 = [ const stacks = [
<PartInner <PartInner
{...{ part: patternProps.parts[0][props.layoutPart], partName: props.layoutPart, gist }} {...{ part: patternProps.parts[0][props.layoutPart], partName: props.layoutPart, gist }}
key={props.layoutPart} key={props.layoutPart}
/>, />,
] ]
// then make a stack component for each remaining stack
for (var stackName in patternProps.stacks) { for (var stackName in patternProps.stacks) {
if (stackName === props.layoutPart) { if (stackName === props.layoutPart) {
continue continue

View file

@ -50,6 +50,7 @@ export const pagesPlugin = ({ size = 'a4', ...settings }) => {
return basePlugin({ ...settings, sheetWidth, sheetHeight }) 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) => { const doScanForBlanks = (stacks, layout, x, y, w, h) => {
let hasContent = false let hasContent = false
for (var s in stacks) { for (var s in stacks) {
@ -113,6 +114,7 @@ const basePlugin = ({
name: partName, name: partName,
draft: (shorthand) => { draft: (shorthand) => {
const layoutData = shorthand.store.get('layoutData') const layoutData = shorthand.store.get('layoutData')
// only actually draft the part if layout data has been set
if (layoutData) { if (layoutData) {
shorthand.macro('addPages', layoutData, shorthand) shorthand.macro('addPages', layoutData, shorthand)
shorthand.part.unhide() shorthand.part.unhide()
@ -122,22 +124,29 @@ const basePlugin = ({
return shorthand.part return shorthand.part
}, },
}) })
// Re-calculate the pattern's config
pattern.getConfig() 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) pattern.createPartForSet(partName, pattern.activeSet)
}, },
postLayout: function (pattern) { postLayout: function (pattern) {
let { height, width, stacks } = pattern let { height, width, stacks } = pattern
if (!responsiveColumns) width = sheetWidth if (!responsiveColumns) width = sheetWidth
// get the layout
const layout = const layout =
typeof pattern.settings[0].layout === 'object' typeof pattern.settings[0].layout === 'object'
? pattern.settings[0].layout ? pattern.settings[0].layout
: pattern.autoLayout : 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) { if (layout?.topLeft) {
height += layout.topLeft.y height += layout.topLeft.y
responsiveColumns && (width += layout.topLeft.x) responsiveColumns && (width += layout.topLeft.x)
} }
// store the layout data so the part can use it during drafting
pattern.setStores[pattern.activeSet].set('layoutData', { pattern.setStores[pattern.activeSet].set('layoutData', {
size: [sheetHeight, sheetWidth], size: [sheetHeight, sheetWidth],
height, height,
@ -145,16 +154,11 @@ const basePlugin = ({
layout, layout,
stacks, 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 // draft the part
// Add pages
// const { macro } = pattern.config.parts[partName].shorthand()
pattern.draftPartForSet(partName, pattern.activeSet) 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) { if (setPatternSize) {
const generatedPageData = pattern.setStores[pattern.activeSet].get('pages') const generatedPageData = pattern.setStores[pattern.activeSet].get('pages')
pattern.width = sheetWidth * generatedPageData.cols pattern.width = sheetWidth * generatedPageData.cols

View file

@ -118,7 +118,6 @@ const WorkbenchWrapper = ({ app, design, preload = false, from = false, layout =
const layout = gist.layouts?.[gist._state.view] || gist.layout || true const layout = gist.layouts?.[gist._state.view] || gist.layout || true
// hand it separately to the design // hand it separately to the design
draft = new design({ ...gist, layout }) draft = new design({ ...gist, layout })
console.log({ draft, design, gist })
//draft.__init() //draft.__init()
// add theme to svg renderer // add theme to svg renderer