From 1c0ca81578e9fdc5043dbc19d9ed9178315300d6 Mon Sep 17 00:00:00 2001 From: Enzo Volkmann Date: Mon, 9 Sep 2024 09:10:21 +0200 Subject: [PATCH] fix(is-layout-field): include `typeof`/`null` check --- index.js | 2 +- src/index.js | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index b1aa5b4..de6b8b1 100644 --- a/index.js +++ b/index.js @@ -1 +1 @@ -(function(){"use strict";const o="volkmann-design-code/kirby-layout-attributes";window[o]=window[o]??{},window[o].functions=window[o].functions??{},window[o].functions.isLayoutField=n=>Array.isArray(n)&&n.length>0&&n.every(t=>"attrs"in t&&"columns"in t&&"id"in t&&typeof t.attrs=="object"&&Array.isArray(t.columns)),window[o].functions.addLayoutAttrs=n=>{const t=n.columns[0].id;let e=document.querySelector(`.k-layout:has(.k-layout-column[id="${t}"])`);if(!e)return;const a=Object.keys(n.attrs);for(const s of a){const i=n.attrs[s];e.setAttribute(`data-attr-${s}`,i),e.style.setProperty(`--attr-${s}`,i)}},window.panel.plugin("volkmann-design-code/kirby-layout-attributes",{created(n){n.$store.subscribeAction({after:(t,e)=>{var a;if(t.type==="content/create"&&setTimeout(()=>{for(const s in t.payload.content){const i=t.payload.content[s];if(window[o].functions.isLayoutField(i))for(const u of i)window[o].functions.addLayoutAttrs(u)}},100),t.type==="content/update"){const s=(a=t.payload)==null?void 0:a[1];if(window[o].functions.isLayoutField(s))for(const i of s)window[o].functions.addLayoutAttrs(i)}}})}})})(); +(function(){"use strict";const o="volkmann-design-code/kirby-layout-attributes";window[o]=window[o]??{},window[o].functions=window[o].functions??{},window[o].functions.isLayoutField=n=>Array.isArray(n)&&n.length>0&&n.every(t=>typeof t=="object"&&t!==null&&"attrs"in t&&"columns"in t&&"id"in t&&typeof t.attrs=="object"&&Array.isArray(t.columns)),window[o].functions.addLayoutAttrs=n=>{const t=n.columns[0].id;let e=document.querySelector(`.k-layout:has(.k-layout-column[id="${t}"])`);if(!e)return;const a=Object.keys(n.attrs);for(const s of a){const i=n.attrs[s];e.setAttribute(`data-attr-${s}`,i),e.style.setProperty(`--attr-${s}`,i)}},window.panel.plugin("volkmann-design-code/kirby-layout-attributes",{created(n){n.$store.subscribeAction({after:(t,e)=>{var a;if(t.type==="content/create"&&setTimeout(()=>{for(const s in t.payload.content){const i=t.payload.content[s];if(window[o].functions.isLayoutField(i))for(const u of i)window[o].functions.addLayoutAttrs(u)}},100),t.type==="content/update"){const s=(a=t.payload)==null?void 0:a[1];if(window[o].functions.isLayoutField(s))for(const i of s)window[o].functions.addLayoutAttrs(i)}}})}})})(); diff --git a/src/index.js b/src/index.js index b4e42d2..f5ac503 100755 --- a/src/index.js +++ b/src/index.js @@ -8,6 +8,8 @@ window[pluginNamespace].functions.isLayoutField = (field) => { field.length > 0 && field.every( (entry) => + typeof entry === "object" && + entry !== null && "attrs" in entry && "columns" in entry && "id" in entry &&