From 01574bba9d2af7d50a6baa1b33dc5901fb6f2391 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Mon, 1 Jan 2024 13:32:02 -0400 Subject: html: add mutable option for html/attributes slot descriptions --- src/util/html.js | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'src/util/html.js') 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(); } -- cgit 1.3.0-6-gf8a5