From da76f232740e1b3dbd50709f74f9d551cac11cbd Mon Sep 17 00:00:00 2001 From: Enoch Riese Date: Thu, 20 Apr 2023 10:07:43 -0400 Subject: [PATCH] add back in accidentally deleted method --- packages/core/src/pattern/index.mjs | 4 +-- packages/core/src/pattern/pattern-drafter.mjs | 31 +++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/packages/core/src/pattern/index.mjs b/packages/core/src/pattern/index.mjs index 41e95cf02d8..71521b1b4c8 100644 --- a/packages/core/src/pattern/index.mjs +++ b/packages/core/src/pattern/index.mjs @@ -275,8 +275,8 @@ Pattern.prototype.__init = function () { this.__runHooks('preInit') // Say hello this.store.log.info( - `New \`${this.designConfig?.data?.name || 'No Name'}:` + - `${this.designConfig?.data?.version || 'No version'}\` ` + + `New \`${this.designConfig.data?.name || 'No Name'}:` + + `${this.designConfig.data?.version || 'No version'}\` ` + `pattern using \`@freesewing/core:${version}\`` ) diff --git a/packages/core/src/pattern/pattern-drafter.mjs b/packages/core/src/pattern/pattern-drafter.mjs index 8db3b11c0b7..fe85faed41a 100644 --- a/packages/core/src/pattern/pattern-drafter.mjs +++ b/packages/core/src/pattern/pattern-drafter.mjs @@ -99,6 +99,37 @@ PatternDrafter.prototype.draftPartForSet = function (partName, set) { } } +/** + * Create a part for the given set of settings. + * Handles injection + * @param {String} partName the name of the part to create + * @param {Number} set the settings index + * @private + */ +PatternDrafter.prototype.__createPartForSet = function (partName, set = 0) { + // gotta protect against attacks + if (set === '__proto__') { + throw new Error('malicious attempt at altering Object.prototype. Stopping action') + } + // Create parts + this.activeStore.log.debug(`📦 Creating part \`${partName}\` (set ${set})`) + this.pattern.parts[set][partName] = this.__createPartWithContext(partName, set) + + // Handle inject/inheritance + const parent = this.pattern.config.inject[partName] + if (typeof parent === 'string') { + this.activeStore.log.debug(`Creating part \`${partName}\` from part \`${parent}\``) + try { + this.pattern.parts[set][partName].__inject(this.pattern.parts[set][parent]) + } catch (err) { + this.activeStore.log.error([ + `Could not inject part \`${parent}\` into part \`${partName}\``, + err, + ]) + } + } +} + /** * Instantiates a new Part instance and populates it with the pattern context *