New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@coldwired/actions

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@coldwired/actions - npm Package Compare versions

Comparing version 0.1.1 to 0.2.0

dist/types/src/attribute-observer.d.ts

2

dist/index.cjs.js

@@ -1,1 +0,1 @@

"use strict";var M=(s,e,t)=>{if(!e.has(s))throw TypeError("Cannot "+t)};var r=(s,e,t)=>(M(s,e,"read from private field"),t?t.call(s):e.get(s)),l=(s,e,t)=>{if(e.has(s))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(s):e.set(s,t)},h=(s,e,t,i)=>(M(s,e,"write to private field"),i?i.call(s,t):e.set(s,t),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("@coldwired/utils"),k=require("morphdom");var j=process.env.NODE_ENV==="production",L="Invariant failed";function A(s,e){if(!s){if(j)throw new Error(L);var t=typeof e=="function"?e():e,i=t?"".concat(L,": ").concat(t):L;throw new Error(i)}}var y,g,N;class q{constructor(e,t){l(this,y,void 0);l(this,g,void 0);l(this,N,void 0);h(this,y,e),h(this,g,new MutationObserver(i=>{for(const a of i)this.onAttributeMutation(a)})),h(this,N,t)}observe(){r(this,g).observe(r(this,y),{attributes:!0,attributeFilter:["class"],attributeOldValue:!0,subtree:!0})}disconnect(){r(this,g).disconnect()}onAttributeMutation(e){if(d.isElement(e.target))if(e.oldValue){const t=new Set(e.oldValue.split(/\s/).filter(Boolean));r(this,N).classListChanged(e.target,t)}else r(this,N).classListChanged(e.target,new Set([]))}}y=new WeakMap,g=new WeakMap,N=new WeakMap;var C;class x{constructor(){l(this,C,new WeakMap)}get(e){return r(this,C).get(e)??null}getOrCreate(e){let t=r(this,C).get(e);return t||(t={addedClassNames:new Set,removedClassNames:new Set,touched:!1},r(this,C).set(e,t)),t??null}}C=new WeakMap;function S(s,e,t){s instanceof Document?(A(e instanceof Document,"Cannot morph document to element"),B(s,e,t)):s instanceof Element&&(A(!(e instanceof Document),"Cannot morph element to document"),e instanceof DocumentFragment?F(s,e,t):typeof e=="string"?F(s,d.parseHTMLFragment(e,s.ownerDocument),t):w(s,e,t))}function F(s,e,t){if(e.normalize(),t!=null&&t.childrenOnly){const i=e.ownerDocument.createElement("div");i.append(e),w(s,i,t)}else{const[i,a,...c]=[...e.childNodes].filter(d.isElementOrText);d.isElement(i)?(a&&s.after(a),w(s,i,t)):d.isElement(a)?(s.before(i),w(s,a,t)):(a&&s.after(a),s.replaceWith(i)),s.after(...c)}}function w(s,e,t){const i=t==null?void 0:t.forceAttribute;k(s,e,{childrenOnly:t==null?void 0:t.childrenOnly,onBeforeElUpdated(a,c){var O;const v=i?!!c.closest(`[${i}]`):!1,o=(O=t==null?void 0:t.metadata)==null?void 0:O.get(a);return v&&o&&(d.isFormInputElement(a)||d.isFormOptionElement(a))&&(o.touched=!1),a.isEqualNode(c)?!1:(!v&&o&&(c.classList.add(...o.addedClassNames),c.classList.remove(...o.removedClassNames),o.touched&&(d.isInputElement(a)&&(a.type=="checkbox"||a.type=="radio")?Object.assign(c,{checked:a.checked}):d.isFormOptionElement(a)?Object.assign(c,{selected:a.selected}):d.isFormInputElement(a)&&Object.assign(c,{value:a.value}))),!0)}})}function B(s,e,t){e.head&&P(s.head,s.adoptNode(e.head)),w(s.body,s.adoptNode(e.body),t)}function P(s,e){k(s,e,{childrenOnly:!0,onBeforeElUpdated(t,i){return!t.isEqualNode(i)},onBeforeNodeDiscarded(t){return!d.isLinkElement(t)}})}const V=["after","before","append","prepend","remove","replace","update","dispatch","focus","enable","disable"];var f,b,u,n,p;class H{constructor({element:e,schema:t}){l(this,f,void 0);l(this,b,void 0);l(this,u,new x);l(this,n,void 0);l(this,p,void 0);h(this,f,e),h(this,b,t??{}),h(this,p,{handleEvent:this.handleEvent.bind(this),classListChanged:this.classListChanged.bind(this)}),h(this,n,new q(r(this,f),r(this,p)))}get element(){return r(this,f)}start(){r(this,n).observe(),r(this,f).addEventListener("input",r(this,p))}stop(){r(this,n).disconnect(),r(this,f).removeEventListener("input",r(this,p))}getAction(e){return A(U(e),`Action "${e}" is not supported`),t=>this[e](t)}after({targets:e,fragment:t}){r(this,n).disconnect();for(const i of e)i.after(t.cloneNode(!0));r(this,n).observe()}before({targets:e,fragment:t}){r(this,n).disconnect();for(const i of e)i.before(t.cloneNode(!0));r(this,n).observe()}append({targets:e,fragment:t}){r(this,n).disconnect(),I(e,t);for(const i of e)i.append(t.cloneNode(!0));r(this,n).observe()}prepend({targets:e,fragment:t}){r(this,n).disconnect(),I(e,t);for(const i of e)i.prepend(t.cloneNode(!0));r(this,n).observe()}remove({targets:e}){r(this,n).disconnect();for(const t of e)t.remove();r(this,n).observe()}replace({targets:e,fragment:t}){r(this,n).disconnect();for(const i of e)S(i,t.cloneNode(!0),{forceAttribute:r(this,b).forceAttribute,metadata:r(this,u)});r(this,n).observe()}update({targets:e,fragment:t}){r(this,n).disconnect();for(const i of e)S(i,t.cloneNode(!0),{forceAttribute:r(this,b).forceAttribute,metadata:r(this,u),childrenOnly:!0});r(this,n).observe()}dispatch({targets:e,stream:t}){const i=t.getAttribute("event-type");A(i,"[turbo-stream] event-type must be present");const a=t.getAttribute("event-detail"),c=a?JSON.parse(a):{};if(e.length>0)for(const v of e)d.dispatch(i,{target:v,detail:c});else d.dispatch(i,{detail:c})}focus({targets:e}){for(const t of e)d.focusElement(t)}disable({targets:e}){for(const t of e)"disabled"in t&&(t.disabled=!0)}enable({targets:e}){for(const t of e)"disabled"in t&&(t.disabled=!1)}morph(e,t,i){r(this,n).disconnect(),S(e,t,{forceAttribute:r(this,b).forceAttribute,metadata:r(this,u),...i}),r(this,n).observe()}handleEvent(e){const t=e.composedPath&&e.composedPath()[0]||e.target;e.type=="input"&&d.isFormInputElement(t)&&(r(this,u).getOrCreate(t).touched=!0)}classListChanged(e,t){const i=r(this,u).getOrCreate(e),a=new Set(e.classList),c=T(a,t),v=T(t,a);for(const o of c)i.addedClassNames.add(o),i.removedClassNames.delete(o);for(const o of v)i.removedClassNames.add(o),i.addedClassNames.delete(o)}}f=new WeakMap,b=new WeakMap,u=new WeakMap,n=new WeakMap,p=new WeakMap;function I(s,e){for(const t of J(s,e))t.remove()}function J(s,e){const t=s.flatMap(a=>[...a.children]).filter(a=>!!a.id),i=new Set([...e.children].filter(a=>!!a.id).map(a=>a.id));return t.filter(a=>i.has(a.id))}function T(s,e){return new Set([...s].filter(t=>!e.has(t)))}function U(s){return V.includes(s)}exports.Actions=H;
"use strict";var F=(a,e,t)=>{if(!e.has(a))throw TypeError("Cannot "+t)};var r=(a,e,t)=>(F(a,e,"read from private field"),t?t.call(a):e.get(a)),d=(a,e,t)=>{if(e.has(a))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(a):e.set(a,t)},l=(a,e,t,i)=>(F(a,e,"write to private field"),i?i.call(a,t):e.set(a,t),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("@coldwired/utils"),P=require("morphdom");var H=process.env.NODE_ENV==="production",S="Invariant failed";function h(a,e){if(!a){if(H)throw new Error(S);var t=typeof e=="function"?e():e,i=t?"".concat(S,": ").concat(t):S;throw new Error(i)}}var A,w,m;class V{constructor(e,t){d(this,A,void 0);d(this,w,void 0);d(this,m,void 0);l(this,A,e),l(this,w,new MutationObserver(i=>{for(const s of i)this.onAttributeMutation(s)})),l(this,m,t)}observe(){r(this,w).observe(r(this,A),{attributes:!0,attributeFilter:["class"],attributeOldValue:!0,subtree:!0})}disconnect(){r(this,w).disconnect()}onAttributeMutation(e){if(n.isElement(e.target))if(e.oldValue){const t=new Set(e.oldValue.split(/\s/).filter(Boolean));r(this,m).classListChanged(e.target,t)}else r(this,m).classListChanged(e.target,new Set([]))}}A=new WeakMap,w=new WeakMap,m=new WeakMap;const $=["role","disabled","tab-index","aria-autocomplete","aria-checked","aria-disabled","aria-errormessage","aria-expanded","aria-haspopup","aria-hidden","aria-invalid","aria-label","aria-level","aria-modal","aria-multiline","aria-multiselectable","aria-orientation","aria-placeholder","aria-pressed","aria-readonly","aria-required","aria-selected","aria-sort","aria-valuemax","aria-valuemin","aria-valuenow","aria-valuetext","aria-busy","aria-live","aria-relevant","aria-atomic","aria-dropeffect","aria-grabbed","aria-activedescendant","aria-colcount","aria-colindex","aria-colspan","aria-controls","aria-describedby","aria-description","aria-details","aria-errormessage","aria-flowto","aria-labelledby","aria-owns","aria-posinset","aria-rowcount","aria-rowindex","aria-rowspan","aria-setsize","aria-atomic","aria-busy","aria-controls","aria-current","aria-describedby","aria-description","aria-details","aria-disabled","aria-dropeffect","aria-errormessage","aria-flowto","aria-grabbed","aria-haspopup","aria-hidden","aria-invalid","aria-keyshortcuts","aria-label","aria-labelledby","aria-live","aria-owns","aria-relevant","aria-roledescription"];var O,N,L;class z{constructor(e,t){d(this,O,void 0);d(this,N,void 0);d(this,L,void 0);l(this,O,e),l(this,N,new MutationObserver(i=>{for(const s of i)this.onAttributeMutation(s)})),l(this,L,t)}observe(){r(this,N).observe(r(this,O),{attributes:!0,attributeFilter:$,subtree:!0})}disconnect(){r(this,N).disconnect()}onAttributeMutation(e){if(n.isElement(e.target)&&e.attributeName){const t=e.target.getAttribute(e.attributeName);r(this,L).attributeChanged(e.target,e.attributeName,t)}}}O=new WeakMap,N=new WeakMap,L=new WeakMap;var C;class U{constructor(){d(this,C,new WeakMap)}get(e){return r(this,C).get(e)??null}getOrCreate(e){let t=r(this,C).get(e);return t||(t={addedClassNames:new Set,removedClassNames:new Set,touched:!1,attributes:{}},r(this,C).set(e,t)),t}}C=new WeakMap;function q(a,e,t){a instanceof Document?(h(e instanceof Document,"Cannot morph document to element"),W(a,e,t)):a instanceof Element&&(h(!(e instanceof Document),"Cannot morph element to document"),e instanceof DocumentFragment?T(a,e,t):typeof e=="string"?T(a,n.parseHTMLFragment(e,a.ownerDocument),t):y(a,e,t))}function T(a,e,t){if(e.normalize(),t!=null&&t.childrenOnly){const i=e.ownerDocument.createElement("div");i.append(e),y(a,i,t)}else{const[i,s,...o]=[...e.childNodes].filter(n.isElementOrText);n.isElement(i)?(s&&a.after(s),y(a,i,t)):n.isElement(s)?(a.before(i),y(a,s,t)):(s&&a.after(s),a.replaceWith(i)),a.after(...o)}}function y(a,e,t){const i=t==null?void 0:t.forceAttribute;if(P(a,e,{childrenOnly:t==null?void 0:t.childrenOnly,onBeforeElUpdated(s,o){var M;const _=i?!!o.closest(`[${i}]`):!1,c=(M=t==null?void 0:t.metadata)==null?void 0:M.get(s);if(_&&c&&(n.isFormInputElement(s)||n.isFormOptionElement(s))&&(c.touched=!1),s.isEqualNode(o))return!1;if(!_&&c){o.classList.add(...c.addedClassNames),o.classList.remove(...c.removedClassNames);for(const[x,k]of Object.entries(c.attributes))k==null?o.removeAttribute(x):o.setAttribute(x,k);c.touched&&(n.isInputElement(s)&&(s.type=="checkbox"||s.type=="radio")?Object.assign(o,{checked:s.checked}):n.isFormOptionElement(s)?Object.assign(o,{selected:s.selected}):n.isFormInputElement(s)&&Object.assign(o,{value:s.value}))}return!0}}),i){a.removeAttribute(i);for(const s of[...a.querySelectorAll(`[${i}]`)])s.removeAttribute(i)}}function W(a,e,t){e.head&&G(a.head,a.adoptNode(e.head)),y(a.body,a.adoptNode(e.body),t)}function G(a,e){P(a,e,{childrenOnly:!0,onBeforeElUpdated(t,i){return!t.isEqualNode(i)},onBeforeNodeDiscarded(t){return!n.isLinkElement(t)}})}const B={forceAttribute:"data-turbo-force",hiddenClassName:"hidden"},J=["after","before","append","prepend","remove","replace","update","focus","enable","disable","hide","show"];var u,f,b,p,v,g;class K{constructor({element:e,schema:t}){d(this,u,void 0);d(this,f,void 0);d(this,b,new U);d(this,p,void 0);d(this,v,void 0);d(this,g,void 0);l(this,u,e),l(this,f,{...B,...t}),l(this,g,{handleEvent:this.handleEvent.bind(this),classListChanged:this.classListChanged.bind(this),attributeChanged:this.attributeChanged.bind(this)}),l(this,p,new V(r(this,u),r(this,g))),l(this,v,new z(r(this,u),r(this,g)))}get element(){return r(this,u)}start(){r(this,p).observe(),r(this,v).observe(),r(this,u).addEventListener("input",r(this,g))}stop(){r(this,p).disconnect(),r(this,v).disconnect(),r(this,u).removeEventListener("input",r(this,g))}render(e){this.withoutObservers(()=>{for(const{action:t,...i}of e)this[t](i)})}after(e){this.withoutObservers(()=>this._after(e))}before(e){this.withoutObservers(()=>this._before(e))}append(e){this.withoutObservers(()=>this._append(e))}prepend(e){this.withoutObservers(()=>this._prepend(e))}remove(e){this.withoutObservers(()=>this._remove(e))}replace(e){this.withoutObservers(()=>this._replace(e))}update(e){this.withoutObservers(()=>this._update(e))}focus({targets:e}){for(const t of e)n.focusElement(t)}disable({targets:e}){for(const t of e)"disabled"in t&&(t.disabled=!0)}enable({targets:e}){for(const t of e)"disabled"in t&&(t.disabled=!1)}hide({targets:e}){for(const t of e)t.classList.add(r(this,f).hiddenClassName)}show({targets:e}){for(const t of e)t.classList.remove(r(this,f).hiddenClassName)}morph(e,t,i){this.withoutObservers(()=>{q(e,t,{forceAttribute:r(this,f).forceAttribute,metadata:r(this,b),...i})})}withoutObservers(e){r(this,p).disconnect(),r(this,v).disconnect(),e(),r(this,p).observe(),r(this,v).observe()}_after({targets:e,fragment:t}){h(t,"[actions] fragment is required");for(const i of e)i.after(t.cloneNode(!0))}_before({targets:e,fragment:t}){h(t,"[actions] fragment is required");for(const i of e)i.before(t.cloneNode(!0))}_append({targets:e,fragment:t}){h(t,"[actions] fragment is required"),I(e,t);for(const i of e)i.append(t.cloneNode(!0))}_prepend({targets:e,fragment:t}){h(t,"[actions] fragment is required"),I(e,t);for(const i of e)i.prepend(t.cloneNode(!0))}_remove({targets:e}){for(const t of e)t.remove()}_replace({targets:e,fragment:t}){h(t,"[actions] fragment is required");for(const i of e)q(i,t.cloneNode(!0),{forceAttribute:r(this,f).forceAttribute,metadata:r(this,b)})}_update({targets:e,fragment:t}){h(t,"[actions] fragment is required");for(const i of e)q(i,t.cloneNode(!0),{forceAttribute:r(this,f).forceAttribute,metadata:r(this,b),childrenOnly:!0})}handleEvent(e){const t=e.composedPath&&e.composedPath()[0]||e.target;e.type=="input"&&n.isFormInputElement(t)&&(r(this,b).getOrCreate(t).touched=!0)}classListChanged(e,t){const i=r(this,b).getOrCreate(e),s=new Set(e.classList),o=j(s,t),_=j(t,s);for(const c of o)i.addedClassNames.add(c),i.removedClassNames.delete(c);for(const c of _)i.removedClassNames.add(c),i.addedClassNames.delete(c)}attributeChanged(e,t,i){r(this,b).getOrCreate(e).attributes[t]=i}}u=new WeakMap,f=new WeakMap,b=new WeakMap,p=new WeakMap,v=new WeakMap,g=new WeakMap;function I(a,e){for(const t of Q(a,e))t.remove()}function Q(a,e){const t=a.flatMap(s=>[...s.children]).filter(s=>!!s.id),i=new Set([...e.children].filter(s=>!!s.id).map(s=>s.id));return t.filter(s=>i.has(s.id))}function j(a,e){return new Set([...a].filter(t=>!e.has(t)))}function R(a){return J.includes(a)}class X extends HTMLElement{constructor(){super(),this.style.display="none"}connectedCallback(){var i;const e=this.getAttribute("type"),t=((i=this.parentElement)==null?void 0:i.tagName)=="HEAD"?this.ownerDocument.documentElement:this.previousElementSibling;h(e,'[dispatch-event] must have "type" attribute'),h(t,"[dispatch-event] must have a target element"),n.dispatch(e,{target:t}),this.remove()}}customElements.get("dispatch-event")||customElements.define("dispatch-event",X);function Y(a){return h(R(a),`[actions] action "${a}" is not supported`),a}exports.Actions=K;exports.defaultSchema=B;exports.parseActionName=Y;

@@ -1,34 +0,34 @@

var k = (s, e, t) => {
if (!e.has(s))
var j = (a, e, t) => {
if (!e.has(a))
throw TypeError("Cannot " + t);
};
var r = (s, e, t) => (k(s, e, "read from private field"), t ? t.call(s) : e.get(s)), o = (s, e, t) => {
if (e.has(s))
var r = (a, e, t) => (j(a, e, "read from private field"), t ? t.call(a) : e.get(a)), n = (a, e, t) => {
if (e.has(a))
throw TypeError("Cannot add the same private member more than once");
e instanceof WeakSet ? e.add(s) : e.set(s, t);
}, l = (s, e, t, i) => (k(s, e, "write to private field"), i ? i.call(s, t) : e.set(s, t), t);
import { isElement as S, parseHTMLFragment as F, isElementOrText as P, isFormInputElement as M, isFormOptionElement as x, isInputElement as q, isLinkElement as H, dispatch as T, focusElement as J } from "@coldwired/utils";
import j from "morphdom";
var U = process.env.NODE_ENV === "production", y = "Invariant failed";
function A(s, e) {
if (!s) {
if (U)
throw new Error(y);
var t = typeof e == "function" ? e() : e, i = t ? "".concat(y, ": ").concat(t) : y;
e instanceof WeakSet ? e.add(a) : e.set(a, t);
}, c = (a, e, t, i) => (j(a, e, "write to private field"), i ? i.call(a, t) : e.set(a, t), t);
import { isElement as _, parseHTMLFragment as V, isElementOrText as $, isFormInputElement as q, isFormOptionElement as B, isInputElement as z, isLinkElement as U, focusElement as W, dispatch as G } from "@coldwired/utils";
import P from "morphdom";
var J = process.env.NODE_ENV === "production", x = "Invariant failed";
function l(a, e) {
if (!a) {
if (J)
throw new Error(x);
var t = typeof e == "function" ? e() : e, i = t ? "".concat(x, ": ").concat(t) : x;
throw new Error(i);
}
}
var w, v, N;
class W {
var y, g, w;
class K {
constructor(e, t) {
o(this, w, void 0);
o(this, v, void 0);
o(this, N, void 0);
l(this, w, e), l(this, v, new MutationObserver((i) => {
for (const a of i)
this.onAttributeMutation(a);
})), l(this, N, t);
n(this, y, void 0);
n(this, g, void 0);
n(this, w, void 0);
c(this, y, e), c(this, g, new MutationObserver((i) => {
for (const s of i)
this.onAttributeMutation(s);
})), c(this, w, t);
}
observe() {
r(this, v).observe(r(this, w), {
r(this, g).observe(r(this, y), {
attributes: !0,

@@ -41,66 +41,182 @@ attributeFilter: ["class"],

disconnect() {
r(this, v).disconnect();
r(this, g).disconnect();
}
onAttributeMutation(e) {
if (S(e.target))
if (_(e.target))
if (e.oldValue) {
const t = new Set(e.oldValue.split(/\s/).filter(Boolean));
r(this, N).classListChanged(e.target, t);
r(this, w).classListChanged(e.target, t);
} else
r(this, N).classListChanged(e.target, /* @__PURE__ */ new Set([]));
r(this, w).classListChanged(e.target, /* @__PURE__ */ new Set([]));
}
}
w = new WeakMap(), v = new WeakMap(), N = new WeakMap();
var g;
class $ {
y = new WeakMap(), g = new WeakMap(), w = new WeakMap();
const Q = [
"role",
"disabled",
"tab-index",
"aria-autocomplete",
"aria-checked",
"aria-disabled",
"aria-errormessage",
"aria-expanded",
"aria-haspopup",
"aria-hidden",
"aria-invalid",
"aria-label",
"aria-level",
"aria-modal",
"aria-multiline",
"aria-multiselectable",
"aria-orientation",
"aria-placeholder",
"aria-pressed",
"aria-readonly",
"aria-required",
"aria-selected",
"aria-sort",
"aria-valuemax",
"aria-valuemin",
"aria-valuenow",
"aria-valuetext",
"aria-busy",
"aria-live",
"aria-relevant",
"aria-atomic",
"aria-dropeffect",
"aria-grabbed",
"aria-activedescendant",
"aria-colcount",
"aria-colindex",
"aria-colspan",
"aria-controls",
"aria-describedby",
"aria-description",
"aria-details",
"aria-errormessage",
"aria-flowto",
"aria-labelledby",
"aria-owns",
"aria-posinset",
"aria-rowcount",
"aria-rowindex",
"aria-rowspan",
"aria-setsize",
"aria-atomic",
"aria-busy",
"aria-controls",
"aria-current",
"aria-describedby",
"aria-description",
"aria-details",
"aria-disabled",
"aria-dropeffect",
"aria-errormessage",
"aria-flowto",
"aria-grabbed",
"aria-haspopup",
"aria-hidden",
"aria-invalid",
"aria-keyshortcuts",
"aria-label",
"aria-labelledby",
"aria-live",
"aria-owns",
"aria-relevant",
"aria-roledescription"
];
var A, C, O;
class R {
constructor(e, t) {
n(this, A, void 0);
n(this, C, void 0);
n(this, O, void 0);
c(this, A, e), c(this, C, new MutationObserver((i) => {
for (const s of i)
this.onAttributeMutation(s);
})), c(this, O, t);
}
observe() {
r(this, C).observe(r(this, A), {
attributes: !0,
attributeFilter: Q,
subtree: !0
});
}
disconnect() {
r(this, C).disconnect();
}
onAttributeMutation(e) {
if (_(e.target) && e.attributeName) {
const t = e.target.getAttribute(e.attributeName);
r(this, O).attributeChanged(e.target, e.attributeName, t);
}
}
}
A = new WeakMap(), C = new WeakMap(), O = new WeakMap();
var N;
class X {
constructor() {
o(this, g, /* @__PURE__ */ new WeakMap());
n(this, N, /* @__PURE__ */ new WeakMap());
}
get(e) {
return r(this, g).get(e) ?? null;
return r(this, N).get(e) ?? null;
}
getOrCreate(e) {
let t = r(this, g).get(e);
let t = r(this, N).get(e);
return t || (t = {
addedClassNames: /* @__PURE__ */ new Set(),
removedClassNames: /* @__PURE__ */ new Set(),
touched: !1
}, r(this, g).set(e, t)), t ?? null;
touched: !1,
attributes: {}
}, r(this, N).set(e, t)), t;
}
}
g = new WeakMap();
function L(s, e, t) {
s instanceof Document ? (A(e instanceof Document, "Cannot morph document to element"), z(s, e, t)) : s instanceof Element && (A(!(e instanceof Document), "Cannot morph element to document"), e instanceof DocumentFragment ? B(s, e, t) : typeof e == "string" ? B(
s,
F(e, s.ownerDocument),
N = new WeakMap();
function M(a, e, t) {
a instanceof Document ? (l(e instanceof Document, "Cannot morph document to element"), Y(a, e, t)) : a instanceof Element && (l(!(e instanceof Document), "Cannot morph element to document"), e instanceof DocumentFragment ? F(a, e, t) : typeof e == "string" ? F(
a,
V(e, a.ownerDocument),
t
) : C(s, e, t));
) : m(a, e, t));
}
function B(s, e, t) {
function F(a, e, t) {
if (e.normalize(), t != null && t.childrenOnly) {
const i = e.ownerDocument.createElement("div");
i.append(e), C(s, i, t);
i.append(e), m(a, i, t);
} else {
const [i, a, ...d] = [...e.childNodes].filter(
P
const [i, s, ...d] = [...e.childNodes].filter(
$
);
S(i) ? (a && s.after(a), C(s, i, t)) : S(a) ? (s.before(i), C(s, a, t)) : (a && s.after(a), s.replaceWith(i)), s.after(...d);
_(i) ? (s && a.after(s), m(a, i, t)) : _(s) ? (a.before(i), m(a, s, t)) : (s && a.after(s), a.replaceWith(i)), a.after(...d);
}
}
function C(s, e, t) {
function m(a, e, t) {
const i = t == null ? void 0 : t.forceAttribute;
j(s, e, {
if (P(a, e, {
childrenOnly: t == null ? void 0 : t.childrenOnly,
onBeforeElUpdated(a, d) {
var O;
const p = i ? !!d.closest(`[${i}]`) : !1, c = (O = t == null ? void 0 : t.metadata) == null ? void 0 : O.get(a);
return p && c && (M(a) || x(a)) && (c.touched = !1), a.isEqualNode(d) ? !1 : (!p && c && (d.classList.add(...c.addedClassNames), d.classList.remove(...c.removedClassNames), c.touched && (q(a) && (a.type == "checkbox" || a.type == "radio") ? Object.assign(d, { checked: a.checked }) : x(a) ? Object.assign(d, { selected: a.selected }) : M(a) && Object.assign(d, { value: a.value }))), !0);
onBeforeElUpdated(s, d) {
var S;
const L = i ? !!d.closest(`[${i}]`) : !1, o = (S = t == null ? void 0 : t.metadata) == null ? void 0 : S.get(s);
if (L && o && (q(s) || B(s)) && (o.touched = !1), s.isEqualNode(d))
return !1;
if (!L && o) {
d.classList.add(...o.addedClassNames), d.classList.remove(...o.removedClassNames);
for (const [k, T] of Object.entries(o.attributes))
T == null ? d.removeAttribute(k) : d.setAttribute(k, T);
o.touched && (z(s) && (s.type == "checkbox" || s.type == "radio") ? Object.assign(d, { checked: s.checked }) : B(s) ? Object.assign(d, { selected: s.selected }) : q(s) && Object.assign(d, { value: s.value }));
}
return !0;
}
});
}), i) {
a.removeAttribute(i);
for (const s of [...a.querySelectorAll(`[${i}]`)])
s.removeAttribute(i);
}
}
function z(s, e, t) {
e.head && _(s.head, s.adoptNode(e.head)), C(s.body, s.adoptNode(e.body), t);
function Y(a, e, t) {
e.head && Z(a.head, a.adoptNode(e.head)), m(a.body, a.adoptNode(e.body), t);
}
function _(s, e) {
j(s, e, {
function Z(a, e) {
P(a, e, {
childrenOnly: !0,

@@ -111,7 +227,10 @@ onBeforeElUpdated(t, i) {

onBeforeNodeDiscarded(t) {
return !H(t);
return !U(t);
}
});
}
const G = [
const D = {
forceAttribute: "data-turbo-force",
hiddenClassName: "hidden"
}, E = [
"after",

@@ -124,19 +243,22 @@ "before",

"update",
"dispatch",
"focus",
"enable",
"disable"
"disable",
"hide",
"show"
];
var h, u, f, n, b;
class Z {
var h, u, f, b, p, v;
class ne {
constructor({ element: e, schema: t }) {
o(this, h, void 0);
o(this, u, void 0);
o(this, f, new $());
o(this, n, void 0);
o(this, b, void 0);
l(this, h, e), l(this, u, t ?? {}), l(this, b, {
n(this, h, void 0);
n(this, u, void 0);
n(this, f, new X());
n(this, b, void 0);
n(this, p, void 0);
n(this, v, void 0);
c(this, h, e), c(this, u, { ...D, ...t }), c(this, v, {
handleEvent: this.handleEvent.bind(this),
classListChanged: this.classListChanged.bind(this)
}), l(this, n, new W(r(this, h), r(this, b)));
classListChanged: this.classListChanged.bind(this),
attributeChanged: this.attributeChanged.bind(this)
}), c(this, b, new K(r(this, h), r(this, v))), c(this, p, new R(r(this, h), r(this, v)));
}

@@ -147,53 +269,102 @@ get element() {

start() {
r(this, n).observe(), r(this, h).addEventListener("input", r(this, b));
r(this, b).observe(), r(this, p).observe(), r(this, h).addEventListener("input", r(this, v));
}
stop() {
r(this, n).disconnect(), r(this, h).removeEventListener("input", r(this, b));
r(this, b).disconnect(), r(this, p).disconnect(), r(this, h).removeEventListener("input", r(this, v));
}
getAction(e) {
return A(Q(e), `Action "${e}" is not supported`), (t) => this[e](t);
render(e) {
this.withoutObservers(() => {
for (const { action: t, ...i } of e)
this[t](i);
});
}
after({ targets: e, fragment: t }) {
r(this, n).disconnect();
after(e) {
this.withoutObservers(() => this._after(e));
}
before(e) {
this.withoutObservers(() => this._before(e));
}
append(e) {
this.withoutObservers(() => this._append(e));
}
prepend(e) {
this.withoutObservers(() => this._prepend(e));
}
remove(e) {
this.withoutObservers(() => this._remove(e));
}
replace(e) {
this.withoutObservers(() => this._replace(e));
}
update(e) {
this.withoutObservers(() => this._update(e));
}
focus({ targets: e }) {
for (const t of e)
W(t);
}
disable({ targets: e }) {
for (const t of e)
"disabled" in t && (t.disabled = !0);
}
enable({ targets: e }) {
for (const t of e)
"disabled" in t && (t.disabled = !1);
}
hide({ targets: e }) {
for (const t of e)
t.classList.add(r(this, u).hiddenClassName);
}
show({ targets: e }) {
for (const t of e)
t.classList.remove(r(this, u).hiddenClassName);
}
morph(e, t, i) {
this.withoutObservers(() => {
M(e, t, {
forceAttribute: r(this, u).forceAttribute,
metadata: r(this, f),
...i
});
});
}
withoutObservers(e) {
r(this, b).disconnect(), r(this, p).disconnect(), e(), r(this, b).observe(), r(this, p).observe();
}
_after({ targets: e, fragment: t }) {
l(t, "[actions] fragment is required");
for (const i of e)
i.after(t.cloneNode(!0));
r(this, n).observe();
}
before({ targets: e, fragment: t }) {
r(this, n).disconnect();
_before({ targets: e, fragment: t }) {
l(t, "[actions] fragment is required");
for (const i of e)
i.before(t.cloneNode(!0));
r(this, n).observe();
}
append({ targets: e, fragment: t }) {
r(this, n).disconnect(), I(e, t);
_append({ targets: e, fragment: t }) {
l(t, "[actions] fragment is required"), H(e, t);
for (const i of e)
i.append(t.cloneNode(!0));
r(this, n).observe();
}
prepend({ targets: e, fragment: t }) {
r(this, n).disconnect(), I(e, t);
_prepend({ targets: e, fragment: t }) {
l(t, "[actions] fragment is required"), H(e, t);
for (const i of e)
i.prepend(t.cloneNode(!0));
r(this, n).observe();
}
remove({ targets: e }) {
r(this, n).disconnect();
_remove({ targets: e }) {
for (const t of e)
t.remove();
r(this, n).observe();
}
replace({ targets: e, fragment: t }) {
r(this, n).disconnect();
_replace({ targets: e, fragment: t }) {
l(t, "[actions] fragment is required");
for (const i of e)
L(i, t.cloneNode(!0), {
M(i, t.cloneNode(!0), {
forceAttribute: r(this, u).forceAttribute,
metadata: r(this, f)
});
r(this, n).observe();
}
update({ targets: e, fragment: t }) {
r(this, n).disconnect();
_update({ targets: e, fragment: t }) {
l(t, "[actions] fragment is required");
for (const i of e)
L(i, t.cloneNode(!0), {
M(i, t.cloneNode(!0), {
forceAttribute: r(this, u).forceAttribute,

@@ -203,64 +374,53 @@ metadata: r(this, f),

});
r(this, n).observe();
}
dispatch({ targets: e, stream: t }) {
const i = t.getAttribute("event-type");
A(i, "[turbo-stream] event-type must be present");
const a = t.getAttribute("event-detail"), d = a ? JSON.parse(a) : {};
if (e.length > 0)
for (const p of e)
T(i, { target: p, detail: d });
else
T(i, { detail: d });
}
focus({ targets: e }) {
for (const t of e)
J(t);
}
disable({ targets: e }) {
for (const t of e)
"disabled" in t && (t.disabled = !0);
}
enable({ targets: e }) {
for (const t of e)
"disabled" in t && (t.disabled = !1);
}
morph(e, t, i) {
r(this, n).disconnect(), L(e, t, {
forceAttribute: r(this, u).forceAttribute,
metadata: r(this, f),
...i
}), r(this, n).observe();
}
handleEvent(e) {
const t = e.composedPath && e.composedPath()[0] || e.target;
e.type == "input" && M(t) && (r(this, f).getOrCreate(t).touched = !0);
e.type == "input" && q(t) && (r(this, f).getOrCreate(t).touched = !0);
}
classListChanged(e, t) {
const i = r(this, f).getOrCreate(e), a = new Set(e.classList), d = V(a, t), p = V(t, a);
for (const c of d)
i.addedClassNames.add(c), i.removedClassNames.delete(c);
for (const c of p)
i.removedClassNames.add(c), i.addedClassNames.delete(c);
const i = r(this, f).getOrCreate(e), s = new Set(e.classList), d = I(s, t), L = I(t, s);
for (const o of d)
i.addedClassNames.add(o), i.removedClassNames.delete(o);
for (const o of L)
i.removedClassNames.add(o), i.addedClassNames.delete(o);
}
attributeChanged(e, t, i) {
r(this, f).getOrCreate(e).attributes[t] = i;
}
}
h = new WeakMap(), u = new WeakMap(), f = new WeakMap(), n = new WeakMap(), b = new WeakMap();
function I(s, e) {
for (const t of K(s, e))
h = new WeakMap(), u = new WeakMap(), f = new WeakMap(), b = new WeakMap(), p = new WeakMap(), v = new WeakMap();
function H(a, e) {
for (const t of ee(a, e))
t.remove();
}
function K(s, e) {
const t = s.flatMap((a) => [...a.children]).filter((a) => !!a.id), i = new Set(
[...e.children].filter((a) => !!a.id).map((a) => a.id)
function ee(a, e) {
const t = a.flatMap((s) => [...s.children]).filter((s) => !!s.id), i = new Set(
[...e.children].filter((s) => !!s.id).map((s) => s.id)
);
return t.filter((a) => i.has(a.id));
return t.filter((s) => i.has(s.id));
}
function V(s, e) {
return new Set([...s].filter((t) => !e.has(t)));
function I(a, e) {
return new Set([...a].filter((t) => !e.has(t)));
}
function Q(s) {
return G.includes(s);
function te(a) {
return E.includes(a);
}
class ae extends HTMLElement {
constructor() {
super(), this.style.display = "none";
}
connectedCallback() {
var i;
const e = this.getAttribute("type"), t = ((i = this.parentElement) == null ? void 0 : i.tagName) == "HEAD" ? this.ownerDocument.documentElement : this.previousElementSibling;
l(e, '[dispatch-event] must have "type" attribute'), l(t, "[dispatch-event] must have a target element"), G(e, { target: t }), this.remove();
}
}
customElements.get("dispatch-event") || customElements.define("dispatch-event", ae);
function de(a) {
return l(te(a), `[actions] action "${a}" is not supported`), a;
}
export {
Z as Actions
ne as Actions,
D as defaultSchema,
de as parseActionName
};

@@ -0,10 +1,8 @@

import { Schema } from './schema';
type ActionParams = {
stream: Element;
targets: Element[];
fragment: DocumentFragment;
fragment?: DocumentFragment;
};
type Action = (params: ActionParams) => void;
type Schema = {
forceAttribute?: string;
};
declare const ActionNames: readonly ["after", "before", "append", "prepend", "remove", "replace", "update", "focus", "enable", "disable", "hide", "show"];
type ActionName = typeof ActionNames[number];
export declare class Actions {

@@ -19,20 +17,33 @@ #private;

stop(): void;
getAction(actionName: string): Action;
after({ targets, fragment }: ActionParams): void;
before({ targets, fragment }: ActionParams): void;
append({ targets, fragment }: ActionParams): void;
prepend({ targets, fragment }: ActionParams): void;
remove({ targets }: ActionParams): void;
replace({ targets, fragment }: ActionParams): void;
update({ targets, fragment }: ActionParams): void;
dispatch({ targets, stream }: ActionParams): void;
render(params: ({
action: ActionName;
} & ActionParams)[]): void;
after(params: ActionParams): void;
before(params: ActionParams): void;
append(params: ActionParams): void;
prepend(params: ActionParams): void;
remove(params: ActionParams): void;
replace(params: ActionParams): void;
update(params: ActionParams): void;
focus({ targets }: ActionParams): void;
disable({ targets }: ActionParams): void;
enable({ targets }: ActionParams): void;
hide({ targets }: ActionParams): void;
show({ targets }: ActionParams): void;
morph(from: Element | Document, to: string | Element | Document | DocumentFragment, options?: {
childrenOnly?: boolean;
}): void;
private withoutObservers;
private _after;
private _before;
private _append;
private _prepend;
private _remove;
private _replace;
private _update;
private handleEvent;
private classListChanged;
private attributeChanged;
}
export declare function parseActionName(actionName: string): ActionName;
export {};
export * from './actions';
export * from './schema';

@@ -5,2 +5,3 @@ type MetadataValue = {

touched: boolean;
attributes: Record<string, string | null>;
};

@@ -7,0 +8,0 @@ export declare class Metadata {

@@ -17,3 +17,3 @@ {

},
"version": "0.1.1",
"version": "0.2.0",
"keywords": [

@@ -20,0 +20,0 @@ "turbo"

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc