« get me outta code hell

html: new 'attributes' slot type - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-12-31 22:25:57 -0400
committer(quasar) nebula <qznebula@protonmail.com>2024-01-01 15:19:33 -0400
commit77037e72fad20c6af8a35cf232430fd5e0d7d73f (patch)
treec80e1fc0fc99ce10d8ae2c549582d72f83b2cefa
parentefe22f73ff21257410d8c13ad9c6db9b54540c09 (diff)
html: new 'attributes' slot type
-rw-r--r--src/content/dependencies/linkTemplate.js2
-rw-r--r--src/content/dependencies/linkThing.js2
-rw-r--r--src/util/html.js17
3 files changed, 19 insertions, 2 deletions
diff --git a/src/content/dependencies/linkTemplate.js b/src/content/dependencies/linkTemplate.js
index f3744bdf..a2448cfe 100644
--- a/src/content/dependencies/linkTemplate.js
+++ b/src/content/dependencies/linkTemplate.js
@@ -18,7 +18,7 @@ export default {
     linkless: {type: 'boolean', default: false},
 
     tooltip: {type: 'string'},
-    attributes: {validate: v => v.isAttributes},
+    attributes: {type: 'attributes'},
     color: {validate: v => v.isColor},
     content: {type: 'html'},
   },
diff --git a/src/content/dependencies/linkThing.js b/src/content/dependencies/linkThing.js
index 1dbd2148..7ce6ed99 100644
--- a/src/content/dependencies/linkThing.js
+++ b/src/content/dependencies/linkThing.js
@@ -45,7 +45,7 @@ export default {
     anchor: {type: 'boolean', default: false},
     linkless: {type: 'boolean', default: false},
 
-    attributes: {validate: v => v.isAttributes},
+    attributes: {type: 'attributes'},
     hash: {type: 'string'},
   },
 
diff --git a/src/util/html.js b/src/util/html.js
index 5144a31b..20f51eaf 100644
--- a/src/util/html.js
+++ b/src/util/html.js
@@ -1056,6 +1056,7 @@ export class Template {
           'boolean',
           'symbol',
           'html',
+          'attributes',
         ];
 
         if (slotDescription.type === 'function') {
@@ -1160,6 +1161,10 @@ export class Template {
           return isHTML(value);
         }
 
+        case 'attributes': {
+          return isAttributesAdditionSingletValue(value);
+        }
+
         case 'string': {
           // Tags and templates are valid in string arguments - they'll be
           // stringified when exposed to the description's .content() function.
@@ -1200,6 +1205,18 @@ export class Template {
       return providedValue;
     }
 
+    if (description.type === 'attributes') {
+      if (!providedValue) {
+        return blankAttributes();
+      }
+
+      if (providedValue instanceof Attributes) {
+        return providedValue.clone();
+      }
+
+      return new Attributes(providedValue);
+    }
+
     if (description.type === 'string') {
       if (providedValue instanceof Tag || providedValue instanceof Template) {
         return providedValue.toString();