chore(plugin-title): Changes for v3. See #2856
This commit is contained in:
parent
3e445a8401
commit
f56e67d007
2 changed files with 32 additions and 26 deletions
|
@ -31,7 +31,7 @@ export const plugin = {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
macros: {
|
macros: {
|
||||||
title: function (so) {
|
title: function (so, { points, scale, locale, store }) {
|
||||||
const prefix = so.prefix || ''
|
const prefix = so.prefix || ''
|
||||||
|
|
||||||
// Passing `false` will remove the title
|
// Passing `false` will remove the title
|
||||||
|
@ -43,7 +43,7 @@ export const plugin = {
|
||||||
`_${prefix}_titleFor`,
|
`_${prefix}_titleFor`,
|
||||||
`_${prefix}_exportDate`,
|
`_${prefix}_exportDate`,
|
||||||
])
|
])
|
||||||
delete this.points[id]
|
delete points[id]
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,36 +59,36 @@ export const plugin = {
|
||||||
}
|
}
|
||||||
|
|
||||||
so = { ...defaults, ...so }
|
so = { ...defaults, ...so }
|
||||||
so.scale = so.scale * this.context.settings.scale
|
so.scale = so.scale * scale
|
||||||
let overwrite = true
|
let overwrite = true
|
||||||
if (so.append) overwrite = false
|
if (so.append) overwrite = false
|
||||||
this.points[`_${prefix}_titleNr`] = so.at
|
points[`_${prefix}_titleNr`] = so.at
|
||||||
.clone()
|
.clone()
|
||||||
.attr('data-text', so.nr, overwrite)
|
.attr('data-text', so.nr, overwrite)
|
||||||
.attr('data-text-class', 'text-4xl fill-note font-bold')
|
.attr('data-text-class', 'text-4xl fill-note font-bold')
|
||||||
.attr('data-text-transform', transform(so.at))
|
.attr('data-text-transform', transform(so.at))
|
||||||
let shift = 8
|
let shift = 8
|
||||||
if (so.title) {
|
if (so.title) {
|
||||||
this.points[`_${prefix}_titleName`] = so.at
|
points[`_${prefix}_titleName`] = so.at
|
||||||
.shift(-90 - so.rotation, shift * so.scale)
|
.shift(-90 - so.rotation, shift * so.scale)
|
||||||
.attr('data-text', so.title)
|
.attr('data-text', so.title)
|
||||||
.attr('data-text-class', 'text-lg fill-current font-bold')
|
.attr('data-text-class', 'text-lg fill-current font-bold')
|
||||||
.attr('data-text-transform', transform(so.at.shift(-90 - so.rotation, 13 * so.scale)))
|
.attr('data-text-transform', transform(so.at.shift(-90 - so.rotation, 13 * so.scale)))
|
||||||
shift += 8
|
shift += 8
|
||||||
}
|
}
|
||||||
let name = this.context.config?.data?.name || 'No Name'
|
let name = store.data?.name || 'No Name'
|
||||||
name = name.replace('@freesewing/', '')
|
name = name.replace('@freesewing/', '')
|
||||||
this.points[`_${prefix}_titlePattern`] = so.at
|
points[`_${prefix}_titlePattern`] = so.at
|
||||||
.shift(-90 - so.rotation, shift * so.scale)
|
.shift(-90 - so.rotation, shift * so.scale)
|
||||||
.attr('data-text', name)
|
.attr('data-text', name)
|
||||||
.attr('data-text', 'v' + (this.context.config?.data?.version || 'No Version'))
|
.attr('data-text', 'v' + (store.data?.version || 'No Version'))
|
||||||
.attr('data-text-class', 'fill-note')
|
.attr('data-text-class', 'fill-note')
|
||||||
.attr('data-text-transform', transform(so.at.shift(-90 - so.rotation, shift * so.scale)))
|
.attr('data-text-transform', transform(so.at.shift(-90 - so.rotation, shift * so.scale)))
|
||||||
if (this.context.settings.metadata && this.context.settings.metadata.for) {
|
if (store.data.for) {
|
||||||
shift += 8
|
shift += 8
|
||||||
this.points[`_${prefix}_titleFor`] = so.at
|
points[`_${prefix}_titleFor`] = so.at
|
||||||
.shift(-90 - so.rotation, shift * so.scale)
|
.shift(-90 - so.rotation, shift * so.scale)
|
||||||
.attr('data-text', '( ' + this.context.settings.metadata.for + ' )')
|
.attr('data-text', '( ' + store.data.for + ' )')
|
||||||
.attr('data-text-class', 'fill-current font-bold')
|
.attr('data-text-class', 'fill-current font-bold')
|
||||||
.attr('data-text-transform', transform(so.at.shift(-90 - so.rotation, shift * so.scale)))
|
.attr('data-text-transform', transform(so.at.shift(-90 - so.rotation, shift * so.scale)))
|
||||||
}
|
}
|
||||||
|
@ -98,11 +98,11 @@ export const plugin = {
|
||||||
let mins = now.getMinutes()
|
let mins = now.getMinutes()
|
||||||
if (hours < 10) hours = `0${hours}`
|
if (hours < 10) hours = `0${hours}`
|
||||||
if (mins < 10) mins = `0${mins}`
|
if (mins < 10) mins = `0${mins}`
|
||||||
this.points[`_${prefix}_exportDate`] = so.at
|
points[`_${prefix}_exportDate`] = so.at
|
||||||
.shift(-90 - so.rotation, shift * so.scale)
|
.shift(-90 - so.rotation, shift * so.scale)
|
||||||
.attr(
|
.attr(
|
||||||
'data-text',
|
'data-text',
|
||||||
now.toLocaleDateString(this.context.settings.locale || 'en', {
|
now.toLocaleDateString(locale || 'en', {
|
||||||
weekday: 'long',
|
weekday: 'long',
|
||||||
year: 'numeric',
|
year: 'numeric',
|
||||||
month: 'short',
|
month: 'short',
|
||||||
|
|
|
@ -8,35 +8,37 @@ describe('Title Plugin Tests', () => {
|
||||||
it('Should run the title macro', () => {
|
it('Should run the title macro', () => {
|
||||||
const part = {
|
const part = {
|
||||||
name: 'test',
|
name: 'test',
|
||||||
draft: ({ points, Point, macro }) => {
|
draft: ({ points, Point, macro, part }) => {
|
||||||
points.anchor = new Point(-12, -34)
|
points.anchor = new Point(-12, -34)
|
||||||
macro('title', {
|
macro('title', {
|
||||||
at: points.anchor,
|
at: points.anchor,
|
||||||
nr: 3,
|
nr: 3,
|
||||||
title: 'unitTest',
|
title: 'unitTest',
|
||||||
})
|
})
|
||||||
|
|
||||||
|
return part
|
||||||
},
|
},
|
||||||
|
plugins: [plugin],
|
||||||
}
|
}
|
||||||
const Pattern = new Design({
|
const Pattern = new Design({
|
||||||
data: { name: 'testPattern', version: 99 },
|
data: { name: 'testPattern', version: 99 },
|
||||||
parts: [part],
|
parts: [part],
|
||||||
plugins: [plugin],
|
|
||||||
})
|
})
|
||||||
const pattern = new Pattern()
|
const pattern = new Pattern()
|
||||||
pattern.draft().render()
|
pattern.draft().render()
|
||||||
let p = pattern.parts.test.points.__titleNr
|
let p = pattern.parts[0].test.points.__titleNr
|
||||||
expect(p.x).to.equal(-12)
|
expect(p.x).to.equal(-12)
|
||||||
expect(p.y).to.equal(-34)
|
expect(p.y).to.equal(-34)
|
||||||
expect(p.attributes.get('data-text')).to.equal('3')
|
expect(p.attributes.get('data-text')).to.equal('3')
|
||||||
expect(p.attributes.get('data-text-class')).to.equal('text-4xl fill-note font-bold')
|
expect(p.attributes.get('data-text-class')).to.equal('text-4xl fill-note font-bold')
|
||||||
expect(p.attributes.get('data-text-x')).to.equal('-12')
|
expect(p.attributes.get('data-text-x')).to.equal('-12')
|
||||||
expect(p.attributes.get('data-text-y')).to.equal('-34')
|
expect(p.attributes.get('data-text-y')).to.equal('-34')
|
||||||
p = pattern.parts.test.points.__titleName
|
p = pattern.parts[0].test.points.__titleName
|
||||||
expect(p.attributes.get('data-text')).to.equal('unitTest')
|
expect(p.attributes.get('data-text')).to.equal('unitTest')
|
||||||
expect(p.attributes.get('data-text-class')).to.equal('text-lg fill-current font-bold')
|
expect(p.attributes.get('data-text-class')).to.equal('text-lg fill-current font-bold')
|
||||||
expect(p.attributes.get('data-text-x')).to.equal('-12')
|
expect(p.attributes.get('data-text-x')).to.equal('-12')
|
||||||
expect(p.attributes.get('data-text-y')).to.equal('-26')
|
expect(p.attributes.get('data-text-y')).to.equal('-26')
|
||||||
p = pattern.parts.test.points.__titlePattern
|
p = pattern.parts[0].test.points.__titlePattern
|
||||||
expect(p.attributes.get('data-text')).to.equal('testPattern v99')
|
expect(p.attributes.get('data-text')).to.equal('testPattern v99')
|
||||||
expect(p.attributes.get('data-text-class')).to.equal('fill-note')
|
expect(p.attributes.get('data-text-class')).to.equal('fill-note')
|
||||||
expect(p.attributes.get('data-text-x')).to.equal('-12')
|
expect(p.attributes.get('data-text-x')).to.equal('-12')
|
||||||
|
@ -46,7 +48,7 @@ describe('Title Plugin Tests', () => {
|
||||||
it('Should run the title macro with append flag', () => {
|
it('Should run the title macro with append flag', () => {
|
||||||
const part = {
|
const part = {
|
||||||
name: 'test',
|
name: 'test',
|
||||||
draft: ({ points, Point, macro }) => {
|
draft: ({ points, Point, macro, part }) => {
|
||||||
points.anchor = new Point(-12, -34).attr('data-text', '#')
|
points.anchor = new Point(-12, -34).attr('data-text', '#')
|
||||||
macro('title', {
|
macro('title', {
|
||||||
at: points.anchor,
|
at: points.anchor,
|
||||||
|
@ -54,16 +56,18 @@ describe('Title Plugin Tests', () => {
|
||||||
title: 'unitTest',
|
title: 'unitTest',
|
||||||
append: true,
|
append: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
return part
|
||||||
},
|
},
|
||||||
|
plugins: [plugin],
|
||||||
}
|
}
|
||||||
const Pattern = new Design({
|
const Pattern = new Design({
|
||||||
data: { name: 'testPattern', version: 99 },
|
data: { name: 'testPattern', version: 99 },
|
||||||
parts: [part],
|
parts: [part],
|
||||||
plugins: [plugin],
|
|
||||||
})
|
})
|
||||||
const pattern = new Pattern()
|
const pattern = new Pattern()
|
||||||
pattern.draft().render()
|
pattern.draft().render()
|
||||||
let p = pattern.parts.test.points.__titleNr
|
let p = pattern.parts[0].test.points.__titleNr
|
||||||
expect(p.x).to.equal(-12)
|
expect(p.x).to.equal(-12)
|
||||||
expect(p.y).to.equal(-34)
|
expect(p.y).to.equal(-34)
|
||||||
expect(p.attributes.get('data-text')).to.equal('# 3')
|
expect(p.attributes.get('data-text')).to.equal('# 3')
|
||||||
|
@ -75,7 +79,7 @@ describe('Title Plugin Tests', () => {
|
||||||
it('Should run the title macro with point prefix', () => {
|
it('Should run the title macro with point prefix', () => {
|
||||||
const part = {
|
const part = {
|
||||||
name: 'test',
|
name: 'test',
|
||||||
draft: ({ points, Point, macro }) => {
|
draft: ({ points, Point, macro, part }) => {
|
||||||
points.anchor = new Point(-12, -34).attr('data-text', '#')
|
points.anchor = new Point(-12, -34).attr('data-text', '#')
|
||||||
macro('title', {
|
macro('title', {
|
||||||
at: points.anchor,
|
at: points.anchor,
|
||||||
|
@ -83,28 +87,30 @@ describe('Title Plugin Tests', () => {
|
||||||
title: 'unitTest',
|
title: 'unitTest',
|
||||||
prefix: 'foo',
|
prefix: 'foo',
|
||||||
})
|
})
|
||||||
|
|
||||||
|
return part
|
||||||
},
|
},
|
||||||
|
plugins: [plugin],
|
||||||
}
|
}
|
||||||
const Pattern = new Design({
|
const Pattern = new Design({
|
||||||
data: { name: 'testPattern', version: 99 },
|
data: { name: 'testPattern', version: 99 },
|
||||||
parts: [part],
|
parts: [part],
|
||||||
plugins: [plugin],
|
|
||||||
})
|
})
|
||||||
const pattern = new Pattern()
|
const pattern = new Pattern()
|
||||||
pattern.draft().render()
|
pattern.draft().render()
|
||||||
let p = pattern.parts.test.points._foo_titleNr
|
let p = pattern.parts[0].test.points._foo_titleNr
|
||||||
expect(p.x).to.equal(-12)
|
expect(p.x).to.equal(-12)
|
||||||
expect(p.y).to.equal(-34)
|
expect(p.y).to.equal(-34)
|
||||||
expect(p.attributes.get('data-text')).to.equal('3')
|
expect(p.attributes.get('data-text')).to.equal('3')
|
||||||
expect(p.attributes.get('data-text-class')).to.equal('text-4xl fill-note font-bold')
|
expect(p.attributes.get('data-text-class')).to.equal('text-4xl fill-note font-bold')
|
||||||
expect(p.attributes.get('data-text-x')).to.equal('-12')
|
expect(p.attributes.get('data-text-x')).to.equal('-12')
|
||||||
expect(p.attributes.get('data-text-y')).to.equal('-34')
|
expect(p.attributes.get('data-text-y')).to.equal('-34')
|
||||||
p = pattern.parts.test.points._foo_titleName
|
p = pattern.parts[0].test.points._foo_titleName
|
||||||
expect(p.attributes.get('data-text')).to.equal('unitTest')
|
expect(p.attributes.get('data-text')).to.equal('unitTest')
|
||||||
expect(p.attributes.get('data-text-class')).to.equal('text-lg fill-current font-bold')
|
expect(p.attributes.get('data-text-class')).to.equal('text-lg fill-current font-bold')
|
||||||
expect(p.attributes.get('data-text-x')).to.equal('-12')
|
expect(p.attributes.get('data-text-x')).to.equal('-12')
|
||||||
expect(p.attributes.get('data-text-y')).to.equal('-26')
|
expect(p.attributes.get('data-text-y')).to.equal('-26')
|
||||||
p = pattern.parts.test.points._foo_titlePattern
|
p = pattern.parts[0].test.points._foo_titlePattern
|
||||||
expect(p.attributes.get('data-text')).to.equal('testPattern v99')
|
expect(p.attributes.get('data-text')).to.equal('testPattern v99')
|
||||||
expect(p.attributes.get('data-text-class')).to.equal('fill-note')
|
expect(p.attributes.get('data-text-class')).to.equal('fill-note')
|
||||||
expect(p.attributes.get('data-text-x')).to.equal('-12')
|
expect(p.attributes.get('data-text-x')).to.equal('-12')
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue