« get me outta code hell

html: add mutable option for html/attributes slot descriptions - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/util
diff options
context:
space:
mode:
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
commit01574bba9d2af7d50a6baa1b33dc5901fb6f2391 (patch)
tree453024aa0ac18bc41b9186e24c3433c46f2a178a /src/util
parent7ac274eac2f9181b06724ca4f786656e501c3f01 (diff)
html: add mutable option for html/attributes slot descriptions
Diffstat (limited to 'src/util')
-rw-r--r--src/util/html.js25
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();
       }