From 016ee9f4352388b1def5817d82b7735e55bd1bf9 Mon Sep 17 00:00:00 2001 From: Owen Graves Date: Fri, 28 Jun 2024 10:15:59 -0500 Subject: [PATCH 1/3] Add support for "for" attribute --- compose.yml | 1 - spago.yaml | 4 ++-- src/DOM/Virtual.js | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/compose.yml b/compose.yml index bf584e5..442a535 100644 --- a/compose.yml +++ b/compose.yml @@ -1,4 +1,3 @@ -version: "3" services: dev: image: ghcr.io/flipstone/purescript-tools:debian-stable-purescript-0.15.15-2024-04-24-8f14f71 diff --git a/spago.yaml b/spago.yaml index 64f354d..c121b1e 100644 --- a/spago.yaml +++ b/spago.yaml @@ -27,6 +27,6 @@ package: build: strict: true workspace: - extra_packages: {} - package_set: + extraPackages: {} + packageSet: registry: 46.2.0 diff --git a/src/DOM/Virtual.js b/src/DOM/Virtual.js index 756e1d4..8e8c4eb 100644 --- a/src/DOM/Virtual.js +++ b/src/DOM/Virtual.js @@ -24,6 +24,7 @@ const NAMESPACED_ATTRS = [ "aria-controls" , "data-popup-opens" , "fill-rule" , "fill" + , "for" , "gradientUnits" , "height" , "line" @@ -114,4 +115,3 @@ export function hookFn(hook) { hook(node)(); } } - From 3db18e8801c6198cb42713a6f79d6cd70387f8a8 Mon Sep 17 00:00:00 2001 From: Owen Graves Date: Fri, 28 Jun 2024 13:11:48 -0500 Subject: [PATCH 2/3] Add prefix support for NAMESPACED_ATTRS --- src/DOM/Virtual.js | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/src/DOM/Virtual.js b/src/DOM/Virtual.js index 8e8c4eb..15963fc 100644 --- a/src/DOM/Virtual.js +++ b/src/DOM/Virtual.js @@ -6,22 +6,16 @@ import * as CE from 'virtual-dom/create-element.js'; 'use strict'; // These are the namespaced element attributes we want to render that -// virtual-dom.js will not -const NAMESPACED_ATTRS = [ "aria-controls" - , "aria-expanded" - , "aria-haspopup" - , "aria-hidden" - , "aria-labelledby" - , "aria-modal" - , "aria-orientation" - , "circle" +// virtual-dom.js will not. This includes special keyword attributes like "class" and "for" and also svg attributes +// +// Since our `Prop` type combines the notion of things like attributes and event handlers +// if we tried in `node` to add all attributes instead of this explicit whitelist we would incorrectly get html like +// "className=" instead of "class=" and things like "onclick=function(a){(e)}..." when the onclick event +// shouldn't be on the html at all +const NAMESPACED_ATTRS = [ "circle" , "class" , "clip-rule" , "d" - , "data-clipboard-text" - , "data-leg-id" - , "data-popup-name" - , "data-popup-opens" , "fill-rule" , "fill" , "for" @@ -33,10 +27,6 @@ const NAMESPACED_ATTRS = [ "aria-controls" , "r" , "rect" , "rx" - , "stroke-linecap" - , "stroke-linejoin" - , "stroke-width" - , "stroke" , "tabindex" , "transform" , "viewBox" @@ -46,6 +36,12 @@ const NAMESPACED_ATTRS = [ "aria-controls" , "y" ]; +// We allow all attributes that start with these strings instead of explicitly listing them in `NAMESPACED_ATTRS` +const NAMESPACED_ATTRS_PREFIXES = [ "aria" + , "data" + , "stroke" + ]; + export function unsafeValue(v) { return v; } export function node(name) { @@ -56,7 +52,7 @@ export function node(name) { for (var i = 0; i < attributeList.length; i++) { var a = attributeList[i]; - if (NAMESPACED_ATTRS.some(v => v == a.key)) { + if (NAMESPACED_ATTRS.some(v => v == a.key) || NAMESPACED_ATTRS_PREFIXES.some(prefix => a.key?.startsWith(prefix))) { nsAttrs[a.key] = a.value; } else { attrs[a.key] = a.value; From 926a9d26f12454bce78b0b32a27b9ebf05f3a609 Mon Sep 17 00:00:00 2001 From: Owen Graves Date: Fri, 28 Jun 2024 14:42:44 -0500 Subject: [PATCH 3/3] Remove hardcoded data attributes --- src/DOM/Erumu/HTML.purs | 2 +- src/DOM/Erumu/HTML/Attributes.purs | 18 +----------------- 2 files changed, 2 insertions(+), 18 deletions(-) diff --git a/src/DOM/Erumu/HTML.purs b/src/DOM/Erumu/HTML.purs index 71e86c6..d778505 100644 --- a/src/DOM/Erumu/HTML.purs +++ b/src/DOM/Erumu/HTML.purs @@ -4,6 +4,6 @@ module DOM.Erumu.HTML , module Events ) where -import DOM.Erumu.HTML.Attributes (action, alt, ariaControls, ariaOrientation, ariaExpanded, ariaHaspopup, ariaHidden, ariaLabelledby, ariaModal, autocomplete, autofocus, cRadius, checked, classN_, class_, classes, clipRule, colSpan, cxCoord, cyCoord, dataClipboardText, dataLegId, dataPopupName, dataPopupOpens, data_, defaultValue, defer, dims, disabled, enctype, fill, fillRule, fontFamily, fontSize, for, gradientUnits, height, href, id_, method, name, noop, offset, placeholder, points, role, rows, rx, selected, src, stroke, strokeLinecap, strokeLinejoin, strokeWidth, style, tabindex, target, title, transform, type_, value, viewBox, width, x1Coord, x2Coord, xCoord, xmlns, y1Coord, y2Coord, yCoord) as Attributes +import DOM.Erumu.HTML.Attributes (action, alt, ariaControls, ariaOrientation, ariaExpanded, ariaHaspopup, ariaHidden, ariaLabelledby, ariaModal, autocomplete, autofocus, cRadius, checked, classN_, class_, classes, clipRule, colSpan, cxCoord, cyCoord, data_, defaultValue, defer, dims, disabled, enctype, fill, fillRule, fontFamily, fontSize, for, gradientUnits, height, href, id_, method, name, noop, offset, placeholder, points, role, rows, rx, selected, src, stroke, strokeLinecap, strokeLinejoin, strokeWidth, style, tabindex, target, title, transform, type_, value, viewBox, width, x1Coord, x2Coord, xCoord, xmlns, y1Coord, y2Coord, yCoord) as Attributes import DOM.Erumu.HTML.Elements (ElementFn, a, address, aside, br, button, circle, code, dd, div_, dl, dt, em, embed, footer, form, graphic, h1, h2, h3,h4, h5, header, hr, i, iframe, img, input, label, li, line, linearGradient, main, nav, noscript, object, ol, option, p, path, polygon, rect, script, section, select, span, stop, strong, svg, table, tbody, td, text, textArea, th, thead, time, tr, ul) as Elements import DOM.Erumu.HTML.Events (clickawayfn, onblur, onclick, onfocus, oninput, onmouseenter, onmouseleave, terminalOnclick) as Events diff --git a/src/DOM/Erumu/HTML/Attributes.purs b/src/DOM/Erumu/HTML/Attributes.purs index cf52094..0d2ee20 100644 --- a/src/DOM/Erumu/HTML/Attributes.purs +++ b/src/DOM/Erumu/HTML/Attributes.purs @@ -19,10 +19,6 @@ module DOM.Erumu.HTML.Attributes , colSpan , cxCoord , cyCoord - , dataClipboardText - , dataLegId - , dataPopupName - , dataPopupOpens , data_ , defaultValue , defer @@ -142,18 +138,6 @@ cyCoord = attribute "cy" data_ :: forall msg. String -> Prop msg data_ = attribute "data" -dataClipboardText :: forall msg. String -> Prop msg -dataClipboardText = attribute "data-clipboard-text" - -dataLegId :: forall msg. String -> Prop msg -dataLegId = attribute "data-leg-id" - -dataPopupName :: forall msg. String -> Prop msg -dataPopupName = attribute "data-popup-name" - -dataPopupOpens :: forall msg. String -> Prop msg -dataPopupOpens = attribute "data-popup-opens" - defaultValue :: forall msg. String -> Prop msg defaultValue = attribute "defaultValue" @@ -288,4 +272,4 @@ y2Coord :: forall msg. String -> Prop msg y2Coord = attribute "y2" yCoord :: forall msg. String -> Prop msg -yCoord = attribute "y" \ No newline at end of file +yCoord = attribute "y"