diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2024-01-01 13:32:02 -0400 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2024-01-01 20:06:21 -0400 |
commit | 01574bba9d2af7d50a6baa1b33dc5901fb6f2391 (patch) | |
tree | 453024aa0ac18bc41b9186e24c3433c46f2a178a | |
parent | 7ac274eac2f9181b06724ca4f786656e501c3f01 (diff) |
html: add mutable option for html/attributes slot descriptions
-rw-r--r-- | src/util/html.js | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/src/util/html.js b/src/util/html.js index 20f51eaf..9221256d 100644 --- a/src/util/html.js +++ b/src/util/html.js @@ -1063,10 +1063,25 @@ export class Template { slotErrors.push(new TypeError(`(${slotName}) Functions shouldn't be provided to slots`)); } else if (slotDescription.type === 'object') { slotErrors.push(new TypeError(`(${slotName}) Provide validate function instead of type: object`)); + } else if ( + (slotDescription.type === 'html' || slotDescription.type === 'attributes') && + !('mutable' in slotDescription) + ) { + slotErrors.push(new TypeError(`(${slotName}) Specify mutable: true/false alongside type: ${slotDescription.type}`)); } else if (!acceptableSlotTypes.includes(slotDescription.type)) { slotErrors.push(new TypeError(`(${slotName}) Expected slot type to be one of ${acceptableSlotTypes.join(', ')}`)); } } + + if ('mutable' in slotDescription) { + if (slotDescription.type !== 'html' && slotDescription.type !== 'attributes') { + slotErrors.push(new TypeError(`(${slotName}) Only specify mutable alongside type: html or attributes`)); + } + + if (typeof slotDescription.mutable !== 'boolean') { + slotErrors.push(new TypeError(`(${slotName}) Expected slot mutable to be boolean`)); + } + } } if (!empty(slotErrors)) { @@ -1198,7 +1213,10 @@ export class Template { return blank(); } - if (providedValue instanceof Tag || providedValue instanceof Template) { + if ( + (providedValue instanceof Tag || providedValue instanceof Template) && + description.mutable + ) { return providedValue.clone(); } @@ -1210,7 +1228,10 @@ export class Template { return blankAttributes(); } - if (providedValue instanceof Attributes) { + if ( + providedValue instanceof Attributes && + description.mutable + ) { return providedValue.clone(); } |