2023-06-06 11:17:14 -05:00
|
|
|
import { useContext } from 'react'
|
2023-06-04 09:59:47 -05:00
|
|
|
import { useTranslation } from 'next-i18next'
|
2023-06-04 23:28:43 -05:00
|
|
|
import { pagesPlugin } from 'shared/plugins/plugin-layout-part.mjs'
|
2023-06-05 16:07:16 -05:00
|
|
|
import {
|
|
|
|
handleExport,
|
|
|
|
ns as exportNs,
|
|
|
|
} from 'shared/components/workbench/exporting/export-handler.mjs'
|
2023-06-04 09:59:47 -05:00
|
|
|
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-05 16:07:16 -05:00
|
|
|
import { defaultPrintSettings, printSettingsPath } from './config.mjs'
|
2023-06-06 11:17:14 -05:00
|
|
|
import { PrintIcon, RightIcon } from 'shared/components/icons.mjs'
|
2023-06-05 16:07:16 -05:00
|
|
|
import { LoadingContext } from 'shared/context/loading-context.mjs'
|
|
|
|
import { useToast } from 'shared/hooks/use-toast.mjs'
|
2023-06-23 17:45:50 -05:00
|
|
|
import { PatternWithMenu, ns as wrapperNs } from '../pattern-with-menu.mjs'
|
2023-08-30 16:57:46 +02:00
|
|
|
import { nsMerge } from 'shared/utils.mjs'
|
2023-06-04 09:59:47 -05:00
|
|
|
|
2023-08-30 16:57:46 +02:00
|
|
|
export const ns = nsMerge(menuNs, wrapperNs, exportNs, 'print')
|
2023-06-04 09:59:47 -05:00
|
|
|
|
|
|
|
export const PrintView = ({
|
|
|
|
design,
|
|
|
|
pattern,
|
|
|
|
patternConfig,
|
|
|
|
settings,
|
2023-06-23 17:45:50 -05:00
|
|
|
setSettings,
|
2023-06-04 09:59:47 -05:00
|
|
|
ui,
|
|
|
|
update,
|
|
|
|
language,
|
|
|
|
account,
|
|
|
|
DynamicDocs,
|
2023-06-05 16:07:16 -05:00
|
|
|
Design,
|
2023-06-04 09:59:47 -05:00
|
|
|
}) => {
|
2023-06-05 16:07:16 -05:00
|
|
|
const { t } = useTranslation(ns)
|
|
|
|
const loading = useContext(LoadingContext)
|
|
|
|
const toast = useToast()
|
2023-06-04 09:59:47 -05:00
|
|
|
|
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
|
2023-06-05 16:07:16 -05:00
|
|
|
const pageSettings = {
|
2023-06-04 23:28:43 -05:00
|
|
|
...defaultSettings,
|
2023-06-05 16:07:16 -05:00
|
|
|
...get(ui, printSettingsPath, {}),
|
2023-06-04 09:59:47 -05:00
|
|
|
}
|
|
|
|
|
2023-06-05 16:07:16 -05:00
|
|
|
pattern.use(pagesPlugin(pageSettings))
|
2023-06-04 09:59:47 -05:00
|
|
|
|
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 exportIt = () => {
|
2023-06-05 16:07:16 -05:00
|
|
|
handleExport({
|
2023-08-06 18:24:14 +00:00
|
|
|
format: pageSettings.size,
|
2023-06-05 16:07:16 -05:00
|
|
|
settings,
|
|
|
|
design,
|
|
|
|
t,
|
|
|
|
Design,
|
|
|
|
ui,
|
|
|
|
startLoading: loading.startLoading,
|
|
|
|
stopLoading: loading.stopLoading,
|
|
|
|
onComplete: () => {},
|
|
|
|
onError: (err) => toast.error(err.message),
|
|
|
|
})
|
2023-06-04 09:59:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2023-06-23 17:45:50 -05:00
|
|
|
<PatternWithMenu
|
2023-08-30 16:57:46 +02:00
|
|
|
noHeader
|
2023-06-23 17:45:50 -05:00
|
|
|
{...{
|
|
|
|
settings,
|
|
|
|
ui,
|
|
|
|
update,
|
|
|
|
control: account.control,
|
2023-08-28 16:55:23 +02:00
|
|
|
account,
|
|
|
|
design,
|
2023-06-23 17:45:50 -05:00
|
|
|
setSettings,
|
|
|
|
title: (
|
2023-08-30 16:57:46 +02:00
|
|
|
<h2 className="text-center lg:text-left capitalize">{t('workbench:printLayout')}</h2>
|
2023-06-23 17:45:50 -05:00
|
|
|
),
|
|
|
|
pattern: (
|
2023-06-04 23:28:43 -05:00
|
|
|
<MovablePattern
|
2023-06-05 16:07:16 -05:00
|
|
|
{...{
|
|
|
|
renderProps,
|
|
|
|
update,
|
|
|
|
immovable: ['pages'],
|
|
|
|
layoutPath: ['layouts', 'print'],
|
|
|
|
showButtons: !ui.hideMovableButtons,
|
|
|
|
}}
|
2023-06-04 23:28:43 -05:00
|
|
|
/>
|
2023-06-23 17:45:50 -05:00
|
|
|
),
|
|
|
|
menu: (
|
2023-08-30 16:57:46 +02:00
|
|
|
<PrintMenu
|
|
|
|
{...{
|
|
|
|
design,
|
|
|
|
pattern,
|
|
|
|
patternConfig,
|
|
|
|
setSettings,
|
|
|
|
settings,
|
|
|
|
ui,
|
|
|
|
update,
|
|
|
|
language,
|
|
|
|
account,
|
|
|
|
DynamicDocs,
|
|
|
|
exportIt,
|
|
|
|
}}
|
|
|
|
/>
|
2023-06-23 17:45:50 -05:00
|
|
|
),
|
|
|
|
}}
|
|
|
|
/>
|
2023-06-04 09:59:47 -05:00
|
|
|
)
|
|
|
|
}
|