fix(shared): There's no utils export in core
This commit is contained in:
parent
65edf0d249
commit
dc98d5acbf
1 changed files with 33 additions and 29 deletions
|
@ -1,8 +1,8 @@
|
|||
import Worker from 'web-worker';
|
||||
import Worker from 'web-worker'
|
||||
import fileSaver from 'file-saver'
|
||||
import { themePlugin } from '@freesewing/plugin-theme'
|
||||
import { pagesPlugin } from '../layout/print/plugin'
|
||||
import {utils} from '@freesewing/core'
|
||||
import { capitalize } from 'shared/utils'
|
||||
|
||||
export const exportTypes = {
|
||||
exportForPrinting: ['a4', 'a3', 'a2', 'a1', 'a0', 'letter', 'tabloid'],
|
||||
|
@ -14,7 +14,7 @@ export const defaultPdfSettings = {
|
|||
size: 'a4',
|
||||
orientation: 'portrait',
|
||||
margin: 10,
|
||||
coverPage: true
|
||||
coverPage: true,
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -29,13 +29,13 @@ export const defaultPdfSettings = {
|
|||
* */
|
||||
export const handleExport = async (format, gist, design, t, app, onComplete, onError) => {
|
||||
// start the loading indicator
|
||||
app.startLoading();
|
||||
app.startLoading()
|
||||
|
||||
// get a worker going
|
||||
const worker = new Worker(new URL('./export-worker.js', import.meta.url), {type: module});
|
||||
const worker = new Worker(new URL('./export-worker.js', import.meta.url), { type: module })
|
||||
|
||||
// listen for the worker's message back
|
||||
worker.addEventListener('message', e => {
|
||||
worker.addEventListener('message', (e) => {
|
||||
// on success
|
||||
if (e.data.success) {
|
||||
// save it out
|
||||
|
@ -60,7 +60,7 @@ export const handleExport = async(format, gist, design, t, app, onComplete, onEr
|
|||
// pdf settings
|
||||
const settings = {
|
||||
...defaultPdfSettings,
|
||||
...(gist._state.layout?.forPrinting?.page || {})
|
||||
...(gist._state.layout?.forPrinting?.page || {}),
|
||||
}
|
||||
|
||||
// arguments to pass to the worker
|
||||
|
@ -76,11 +76,14 @@ export const handleExport = async(format, gist, design, t, app, onComplete, onEr
|
|||
|
||||
// add the theme and translation to the pattern
|
||||
pattern.use(themePlugin, { stripped: format !== 'svg' })
|
||||
pattern.use({
|
||||
pattern.use(
|
||||
{
|
||||
hooks: {
|
||||
insertText: (locale, text, {t}) => t(text)
|
||||
}
|
||||
},{t})
|
||||
insertText: (locale, text, { t }) => t(text),
|
||||
},
|
||||
},
|
||||
{ t }
|
||||
)
|
||||
|
||||
// a specified size should override the gist one
|
||||
if (format !== 'pdf') {
|
||||
|
@ -90,23 +93,25 @@ export const handleExport = async(format, gist, design, t, app, onComplete, onEr
|
|||
try {
|
||||
// add pages to pdf exports
|
||||
if (format !== 'svg') {
|
||||
pattern.use(pagesPlugin({
|
||||
pattern.use(
|
||||
pagesPlugin({
|
||||
...settings,
|
||||
printStyle: true,
|
||||
renderBlanks: false,
|
||||
setPatternSize: true
|
||||
}))
|
||||
setPatternSize: true,
|
||||
})
|
||||
)
|
||||
|
||||
// add the strings that are used on the cover page
|
||||
workerArgs.strings = {
|
||||
design: utils.capitalize(gist.design),
|
||||
design: capitalize(gist.design),
|
||||
tagline: t('common:sloganCome') + '. ' + t('common:sloganStay'),
|
||||
url: window.location.href
|
||||
url: window.location.href,
|
||||
}
|
||||
}
|
||||
|
||||
// draft and render the pattern
|
||||
pattern.draft();
|
||||
pattern.draft()
|
||||
svg = pattern.render()
|
||||
|
||||
// add the svg and pages data to the worker args
|
||||
|
@ -116,10 +121,9 @@ export const handleExport = async(format, gist, design, t, app, onComplete, onEr
|
|||
}
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
app.stopLoading();
|
||||
app.stopLoading()
|
||||
onError && onError(err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// post a message to the worker with all needed data
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue