2023-06-04 09:59:47 -05:00
|
|
|
import { useEffect, useState } from 'react'
|
|
|
|
import { useTranslation } from 'next-i18next'
|
|
|
|
// import { PrintLayoutSettings } from './settings.mjs'
|
|
|
|
// import { Draft } from '../draft/index.mjs'
|
2023-06-04 23:28:43 -05:00
|
|
|
import { pagesPlugin } from 'shared/plugins/plugin-layout-part.mjs'
|
2023-06-04 09:59:47 -05:00
|
|
|
// import {
|
|
|
|
// handleExport,
|
|
|
|
// defaultPdfSettings,
|
|
|
|
// } from 'shared/components/workbench/exporting/export-handler.mjs'
|
|
|
|
// import { Popout } from 'shared/components/popout.mjs'
|
|
|
|
import get from 'lodash.get'
|
2023-06-04 23:28:43 -05:00
|
|
|
import { MovablePattern } from 'shared/components/workbench/pattern/movable/index.mjs'
|
2023-06-04 09:59:47 -05:00
|
|
|
import { PrintMenu, ns as menuNs } from './menu.mjs'
|
2023-06-04 23:28:43 -05:00
|
|
|
import { defaultPrintSettings } from './config.mjs'
|
2023-06-04 09:59:47 -05:00
|
|
|
|
|
|
|
const viewNs = ['print']
|
2023-06-04 23:28:43 -05:00
|
|
|
export const ns = [...viewNs]
|
2023-06-04 09:59:47 -05:00
|
|
|
|
|
|
|
export const PrintView = ({
|
|
|
|
design,
|
|
|
|
pattern,
|
|
|
|
patternConfig,
|
|
|
|
setView,
|
|
|
|
settings,
|
|
|
|
ui,
|
|
|
|
update,
|
|
|
|
language,
|
|
|
|
account,
|
|
|
|
DynamicDocs,
|
|
|
|
}) => {
|
|
|
|
const { t } = useTranslation(viewNs)
|
|
|
|
const [error, setError] = useState(false)
|
|
|
|
|
2023-06-04 23:28:43 -05:00
|
|
|
const defaultSettings = defaultPrintSettings(settings.units)
|
2023-06-04 09:59:47 -05:00
|
|
|
// add the pages plugin to the draft
|
|
|
|
const layoutSettings = {
|
2023-06-04 23:28:43 -05:00
|
|
|
...defaultSettings,
|
|
|
|
...get(ui, ['print', 'page']),
|
2023-06-04 09:59:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
pattern.use(pagesPlugin(layoutSettings))
|
|
|
|
|
2023-06-04 23:28:43 -05:00
|
|
|
let renderProps
|
2023-06-04 09:59:47 -05:00
|
|
|
try {
|
|
|
|
// draft the pattern
|
|
|
|
pattern.draft()
|
2023-06-04 23:28:43 -05:00
|
|
|
renderProps = pattern.getRenderProps()
|
2023-06-04 09:59:47 -05:00
|
|
|
} catch (err) {
|
|
|
|
console.log(err)
|
|
|
|
}
|
|
|
|
const bgProps = { fill: 'none' }
|
|
|
|
|
|
|
|
const exportIt = () => {
|
|
|
|
// setError(false)
|
|
|
|
// handleExport(
|
|
|
|
// 'pdf',
|
|
|
|
// props.gist,
|
|
|
|
// props.design,
|
|
|
|
// t,
|
|
|
|
// props.app,
|
|
|
|
// () => setError(false),
|
|
|
|
// () => setError(true)
|
|
|
|
// )
|
|
|
|
}
|
|
|
|
|
|
|
|
let name = design
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<h2 className="capitalize">{t('layoutThing', { thing: name }) + ': ' + t('forPrinting')}</h2>
|
|
|
|
<div className="flex flex-row">
|
|
|
|
<div className="w-2/3 shrink-0 grow lg:p-4 sticky top-0">
|
2023-06-04 23:28:43 -05:00
|
|
|
<MovablePattern
|
|
|
|
{...{ renderProps, update, immovable: ['pages'], layoutPath: ['layouts', 'print'] }}
|
|
|
|
/>
|
2023-06-04 09:59:47 -05:00
|
|
|
</div>
|
|
|
|
<div className="w-1/3 shrink grow-0 lg:p-4 max-w-2xl h-screen overflow-scroll">
|
|
|
|
<PrintMenu
|
|
|
|
{...{
|
|
|
|
design,
|
|
|
|
pattern,
|
|
|
|
patternConfig,
|
|
|
|
settings,
|
|
|
|
ui,
|
|
|
|
update,
|
|
|
|
language,
|
|
|
|
account,
|
|
|
|
DynamicDocs,
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|