Merge pull request #6079 from freesewing/joost
feat: Changes to handle per-set bust plugin conditionality
This commit is contained in:
commit
96ef465b33
6 changed files with 51 additions and 17 deletions
|
@ -1,3 +1,20 @@
|
||||||
|
Unreleased:
|
||||||
|
Changed:
|
||||||
|
brian:
|
||||||
|
- Always load plugin-bust due to its changes in how it handle conditionality.
|
||||||
|
plugin-bust:
|
||||||
|
- This plugin now uses the `preSetDraft` rather than `preDraft` lifecycle hook
|
||||||
|
- Conditionality has been moved to the `preSetDraft` lifecycle hook, rather than exposing a `withCondition` named export
|
||||||
|
- The plugin will now always be loaded, but will check for each drafted set whether it should make any changes.
|
||||||
|
|
||||||
|
Deprecated:
|
||||||
|
plugin-bust:
|
||||||
|
- The `withCondition` named export is deprecated and will always return true.
|
||||||
|
|
||||||
|
Fixed:
|
||||||
|
hugo:
|
||||||
|
- Add missing dimension id attributes
|
||||||
|
|
||||||
3.2.0:
|
3.2.0:
|
||||||
date: 2024-02-11
|
date: 2024-02-11
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { withCondition as bustPlugin } from '@freesewing/plugin-bust'
|
import { bustPlugin } from '@freesewing/plugin-bust'
|
||||||
|
|
||||||
export const base = {
|
export const base = {
|
||||||
name: 'brian.base',
|
name: 'brian.base',
|
||||||
|
|
|
@ -20,4 +20,7 @@ pattern.on('preDraft', pattern => {
|
||||||
|
|
||||||
## Notes
|
## Notes
|
||||||
|
|
||||||
The `preDraft` hook is rarely used, but it's there if you need it.
|
The `preDraft` hook fires once for all the sets in the pattern.
|
||||||
|
While typically, there is only one set, there might be more.
|
||||||
|
In that case, the [`preSetDraft` lifecycle hook](/reference/hooks/presetdraft) is
|
||||||
|
the per-set equivalent of this hook.
|
||||||
|
|
|
@ -21,4 +21,15 @@ pattern.on('preSetDraft', pattern => {
|
||||||
|
|
||||||
## Notes
|
## Notes
|
||||||
|
|
||||||
The `preSetDraft` hook is rarely used, but it's there if you need it.
|
The `preSetDraft` fires once for each set in the pattern.
|
||||||
|
|
||||||
|
The pattern tracks the active set on the `activeSet` property.
|
||||||
|
So if you are using this hook and would like to get access to teh active set, you can do so like this:
|
||||||
|
|
||||||
|
```js
|
||||||
|
pattern.on('preSetDraft', ({ settings, activeSet }) => {
|
||||||
|
const set = settings[Number(activeSet)]
|
||||||
|
|
||||||
|
// Now set holds the active set of settings
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
|
@ -4,13 +4,12 @@ export const plugin = {
|
||||||
name,
|
name,
|
||||||
version,
|
version,
|
||||||
hooks: {
|
hooks: {
|
||||||
preDraft: function ({ settings }) {
|
preSetDraft: function ({ settings, activeSet }) {
|
||||||
for (const i in settings) {
|
const set = settings[Number(activeSet)]
|
||||||
if (settings[i].measurements) {
|
if (set.measurements && set.options?.draftForHighBust && set.measurements?.highBust) {
|
||||||
if (typeof settings[i].measurements.bust === 'undefined') {
|
if (typeof set.measurements.bust === 'undefined') {
|
||||||
settings[i].measurements.bust = settings[i].measurements.chest
|
set.measurements.bust = set.measurements.chest
|
||||||
settings[i].measurements.chest = settings[i].measurements.highBust
|
set.measurements.chest = set.measurements.highBust
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -24,6 +23,11 @@ export const pluginBust = plugin
|
||||||
// Helper method to conditionally load this plugin
|
// Helper method to conditionally load this plugin
|
||||||
export const withCondition = {
|
export const withCondition = {
|
||||||
plugin,
|
plugin,
|
||||||
condition: (settings = false) =>
|
condition: () => {
|
||||||
settings?.options?.draftForHighBust && settings?.measurements?.highBust ? true : false,
|
console.log(
|
||||||
|
"WARNING: The 'withCondition' named export in @freesewing/plugin-bust is deprecated. Conditionality has moved to the preSetDraft lifecycle hook"
|
||||||
|
)
|
||||||
|
|
||||||
|
return true
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,9 +6,10 @@ const measurements = {
|
||||||
chest: 100,
|
chest: 100,
|
||||||
highBust: 90,
|
highBust: 90,
|
||||||
}
|
}
|
||||||
|
const options = { draftForHighBust: true }
|
||||||
|
|
||||||
const Pattern = new Design()
|
const Pattern = new Design()
|
||||||
const pattern = new Pattern({ measurements }).use(plugin)
|
const pattern = new Pattern({ measurements, options }).use(plugin)
|
||||||
pattern.draft()
|
pattern.draft()
|
||||||
|
|
||||||
describe('Bust plugin Tests', () => {
|
describe('Bust plugin Tests', () => {
|
||||||
|
@ -18,9 +19,7 @@ describe('Bust plugin Tests', () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should copy measurement from chest to bust and from highBust to chest', function () {
|
it('Should copy measurement from chest to bust and from highBust to chest', function () {
|
||||||
const testPattern = new Design({
|
const testPattern = new Design({ measurements: [], options })
|
||||||
measurements: [],
|
|
||||||
})
|
|
||||||
const pattern = new testPattern().use(plugin)
|
const pattern = new testPattern().use(plugin)
|
||||||
const userMeasurements = { chest: 50, highBust: 60 }
|
const userMeasurements = { chest: 50, highBust: 60 }
|
||||||
pattern.settings[0].measurements = userMeasurements
|
pattern.settings[0].measurements = userMeasurements
|
||||||
|
@ -30,7 +29,7 @@ describe('Bust plugin Tests', () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
it('Should not overwrite existing bust measurements', function () {
|
it('Should not overwrite existing bust measurements', function () {
|
||||||
let config = { measurements: [] }
|
let config = { measurements: [], options }
|
||||||
const testPattern = new Design(config, plugin)
|
const testPattern = new Design(config, plugin)
|
||||||
let pattern = new testPattern()
|
let pattern = new testPattern()
|
||||||
let userMeasurements = { chest: 50, highBust: 60, bust: 55 }
|
let userMeasurements = { chest: 50, highBust: 60, bust: 55 }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue