1
0
Fork 0

fix(core): Allow run-time hiding of parts

This commit is contained in:
Joost De Cock 2022-09-28 18:07:32 +02:00
parent d84dab5105
commit 5a9a7b2b91

View file

@ -181,6 +181,7 @@ Pattern.prototype.getConfig = function () {
* @return {object} this - The Pattern instance * @return {object} this - The Pattern instance
*/ */
Pattern.prototype.getRenderProps = function () { Pattern.prototype.getRenderProps = function () {
this.store.log.info('Gathering render props')
// Run pre-render hook // Run pre-render hook
let svg = new Svg(this) let svg = new Svg(this)
svg.hooks = this.hooks svg.hooks = this.hooks
@ -194,15 +195,6 @@ Pattern.prototype.getRenderProps = function () {
props.height = this.height props.height = this.height
props.autoLayout = this.autoLayout props.autoLayout = this.autoLayout
props.settings = this.settings props.settings = this.settings
props.logs = {
pattern: this.store.logs,
sets: this.setStores.map((store) => ({
debug: store.logs.debug,
info: store.logs.info,
error: store.logs.error,
warning: store.logs.warning,
})),
}
props.parts = [] props.parts = []
for (const set of this.parts) { for (const set of this.parts) {
const setParts = {} const setParts = {}
@ -212,6 +204,10 @@ Pattern.prototype.getRenderProps = function () {
...set[p].asProps(), ...set[p].asProps(),
store: this.setStores[set[p].set], store: this.setStores[set[p].set],
} }
} else if (this.setStores[set?.set]) {
this.setStores[set.set].log.info(
`Part${p} is hidden in set ${set.set}. Not adding to render props`
)
} }
} }
props.parts.push(setParts) props.parts.push(setParts)
@ -220,7 +216,16 @@ Pattern.prototype.getRenderProps = function () {
for (let s in this.stacks) { for (let s in this.stacks) {
if (!this.__isStackHidden(s)) { if (!this.__isStackHidden(s)) {
props.stacks[s] = this.stacks[s].asProps() props.stacks[s] = this.stacks[s].asProps()
} } else this.store.log.info(`Stack ${s} is hidden. Skipping in render props.`)
}
props.logs = {
pattern: this.store.logs,
sets: this.setStores.map((store) => ({
debug: store.logs.debug,
info: store.logs.info,
error: store.logs.error,
warning: store.logs.warning,
})),
} }
return props return props
@ -706,6 +711,7 @@ Pattern.prototype.__isPartHidden = function (partName) {
if (this.__designParts?.[partName]?.hideAll) return true if (this.__designParts?.[partName]?.hideAll) return true
if (this.__mutated.partHide?.[partName]) return true if (this.__mutated.partHide?.[partName]) return true
if (this.__mutated.partHideAll?.[partName]) return true if (this.__mutated.partHideAll?.[partName]) return true
if (this.parts?.[this.activeSet]?.[partName]?.hidden) return true
return false return false
} }
@ -731,6 +737,7 @@ Pattern.prototype.__isStackHidden = function (stackName) {
if (this.__designParts?.[partName]?.hideAll) return true if (this.__designParts?.[partName]?.hideAll) return true
if (this.__mutated.partHide?.[partName]) return true if (this.__mutated.partHide?.[partName]) return true
if (this.__mutated.partHideAll?.[partName]) return true if (this.__mutated.partHideAll?.[partName]) return true
if (this.parts?.[this.activeSet]?.[partName]?.hidden) return true
} }
return false return false
@ -1239,7 +1246,7 @@ Pattern.prototype.__resolveParts = function (count = 0, distance = 0) {
if (part.hideAll) this.__mutated.partHide[part.name] = true if (part.hideAll) this.__mutated.partHide[part.name] = true
// Inject (from) // Inject (from)
if (part.from) { if (part.from) {
if (part.hideDependencies || part.hideAll) { if (part.hideDependencies) {
// Don't mutate the part, keep this info in the pattern object // Don't mutate the part, keep this info in the pattern object
this.__mutated.partHide[part.from.name] = true this.__mutated.partHide[part.from.name] = true
this.__mutated.partHideAll[part.from.name] = true this.__mutated.partHideAll[part.from.name] = true
@ -1258,9 +1265,6 @@ Pattern.prototype.__resolveParts = function (count = 0, distance = 0) {
this.__addDependency(name, part, dep) this.__addDependency(name, part, dep)
} }
} else { } else {
if (part.hideDependencies) {
this.__mutated.partHide[part.after.name] = true
}
this.__mutated.partDistance[part.after.name] = distance this.__mutated.partDistance[part.after.name] = distance
this.__designParts[part.after.name] = part.after this.__designParts[part.after.name] = part.after
this.__addDependency(name, part, part.after) this.__addDependency(name, part, part.after)