@ramstack/alpinegear-main 1.4.4 → 1.4.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -114,6 +114,7 @@ function watch(get_value, callback, options = null) {
114
114
  let new_value;
115
115
  let old_value;
116
116
  let initialized = false;
117
+ let timer_id;
117
118
 
118
119
  const handle = effect(() => {
119
120
  new_value = get_value();
@@ -125,7 +126,7 @@ function watch(get_value, callback, options = null) {
125
126
 
126
127
  if (initialized || (options?.immediate ?? true)) {
127
128
  // Prevent the watcher from detecting its own dependencies.
128
- setTimeout(() => {
129
+ timer_id = setTimeout(() => {
129
130
  callback(new_value, old_value);
130
131
  old_value = new_value;
131
132
  });
@@ -134,7 +135,10 @@ function watch(get_value, callback, options = null) {
134
135
  initialized = true;
135
136
  });
136
137
 
137
- return () => release(handle);
138
+ return () => {
139
+ clearTimeout(timer_id);
140
+ release(handle);
141
+ }
138
142
  }
139
143
 
140
144
  const canonical_names = create_map(
@@ -448,7 +452,6 @@ function collect_group_values(el, values) {
448
452
 
449
453
  function plugin$5({ directive, evaluateLater, mutateDom }) {
450
454
  directive("format", (el, { modifiers }, { effect }) => {
451
- const placeholder_regex = /{{(?<expr>.+?)}}/g;
452
455
  const is_once = has_modifier(modifiers, "once");
453
456
  const has_format_attr = el => el.hasAttribute("x-format");
454
457
 
@@ -500,7 +503,7 @@ function plugin$5({ directive, evaluateLater, mutateDom }) {
500
503
  }
501
504
 
502
505
  function process_text_node(node) {
503
- const tokens = node.textContent.split(placeholder_regex);
506
+ const tokens = node.textContent.split(/{{(?<expr>.+?)}}/g);
504
507
 
505
508
  if (tokens.length > 1) {
506
509
  const fragment = new DocumentFragment();
@@ -525,10 +528,19 @@ function plugin$5({ directive, evaluateLater, mutateDom }) {
525
528
 
526
529
  function process_attributes(node) {
527
530
  for (let attr of node.attributes) {
528
- const matches = [...attr.value.matchAll(placeholder_regex)];
531
+ const matches = [...attr.value.matchAll(/{{(?<expr>.+?)}}/g)];
529
532
  if (matches.length) {
533
+ const getters = new Map(
534
+ matches.map(m => [
535
+ m.groups.expr,
536
+ create_getter(
537
+ evaluateLater,
538
+ node,
539
+ m.groups.expr)]));
540
+
530
541
  const template = attr.value;
531
- update(() => attr.value = template.replace(placeholder_regex, (_, expr) => create_getter(evaluateLater, node, expr)()));
542
+
543
+ update(() => attr.value = template.replace(/{{(?<expr>.+?)}}/g, (_, expr) => getters.get(expr)()));
532
544
  }
533
545
  }
534
546
  }
@@ -669,7 +681,7 @@ function plugin$2(alpine) {
669
681
 
670
682
  const tpl = document.getElementById(expression);
671
683
 
672
- if (!is_template(tpl)) {
684
+ if (!tpl || !is_template(tpl)) {
673
685
  warn("x-template directive can only reference the template tag");
674
686
  return;
675
687
  }
@@ -1 +1 @@
1
- function e(e,...t){const n=e(...t);return()=>{let e;return n(t=>e=t),t=e,"function"==typeof t?.get?e.get():e;var t}}function t(e,...t){const n=e(...t);t[t.length-1]=`${t.at(-1)} = __val`;const o=e(...t);return e=>{let t;n(e=>t=e),function(e){return"function"==typeof e?.set}(t)?t.set(e):o(()=>{},{scope:{__val:e}})}}const n=Symbol();let o;const a=(...e)=>console.warn("alpinegear.js:",...e),r=Array.isArray,c=e=>null==e,i=e=>"checkbox"===e.type||"radio"===e.type,l=e=>e.matches("template"),u=e=>e.nodeType===Node.ELEMENT_NODE,s=e=>r(e)?e:[e],d=(e,t)=>e==t,f=(e,t)=>e.findIndex(e=>e==t),p=(e,t)=>e.includes(t),m=(e,t,n,o)=>(e.addEventListener(t,n,o),()=>e.removeEventListener(t,n,o)),h=e=>"object"==typeof e?JSON.parse(JSON.stringify(e)):e;function v(e,t,n=null){const{effect:o,release:a}=Alpine;let r,c,i=!1;const l=o(()=>{r=e(),i||(n?.deep&&JSON.stringify(r),c=r),(i||(n?.immediate??1))&&setTimeout(()=>{t(r,c),c=r}),i=!0});return()=>a(l)}const b=new Map("value,checked,files,innerHTML,innerText,textContent,videoHeight,videoWidth,naturalHeight,naturalWidth,clientHeight,clientWidth,offsetHeight,offsetWidth,indeterminate,open,group".split(",").map(e=>[e.trim().toLowerCase(),e.trim()]));function g({directive:l,entangle:u,evaluateLater:g,mapAttributes:x,mutateDom:T,prefixed:_}){x(e=>({name:e.name.replace(/^&/,_("bound:")),value:e.value})),l("bound",(l,{expression:x,value:_,modifiers:k},{effect:N,cleanup:y})=>{if(!_)return void a("x-bound directive expects the presence of a bound property name");const E=l.tagName.toUpperCase();x=x?.trim();const L=b.get(_.trim().replace("-","").toLowerCase());x||=L;const w=e(g,l,x),D=t(g,l,x),S=()=>d(l[L],w())||T(()=>l[L]=w()),A=()=>D((e=>"number"===e.type||"range"===e.type)(l)?function(e){return""===e?null:+e}(l[L]):l[L]);let C;switch(L){case"value":!function(){switch(E){case"INPUT":case"TEXTAREA":c(w())&&A(),N(S),y(m(l,"input",A)),C=!0;break;case"SELECT":setTimeout(()=>{c(w())&&A(),N(()=>function(e,t){for(const n of e.options)n.selected=f(t,n.value)>=0}(l,s(w()??[]))),y(m(l,"change",()=>D(function(e){return e.multiple?[...e.selectedOptions].map(e=>e.value):e.value}(l))))}),C=!0}}();break;case"checked":i(l)&&(N(S),y(m(l,"change",A)),C=!0);break;case"files":"file"===l.type&&(w()instanceof FileList||A(),N(S),y(m(l,"input",A)),C=!0);break;case"innerHTML":case"innerText":case"textContent":l.isContentEditable&&(c(w())&&A(),N(S),y(m(l,"input",A)),C=!0);break;case"videoHeight":case"videoWidth":H("VIDEO","resize");break;case"naturalHeight":case"naturalWidth":H("IMG","load");break;case"clientHeight":case"clientWidth":case"offsetHeight":case"offsetWidth":y(function(e,t){return o??=new ResizeObserver(e=>{for(const t of e)for(const e of t.target[n]?.values()??[])e(t)}),e[n]??=new Set,e[n].add(t),o.observe(e),()=>{e[n].delete(t),e[n].size||(o.unobserve(e),e[n]=null)}}(l,A)),C=!0;break;case"indeterminate":"checkbox"===l.type&&(c(w())&&A(),N(S),y(m(l,"change",A)),C=!0);break;case"open":!function(){const[e,t]=["DETAILS"===E,"DIALOG"===E];(e||t)&&((t||c(w()))&&A(),e&&N(S),y(m(l,"toggle",A)),C=!0)}();break;case"group":i(l)&&(l.name||T(()=>l.name=x),N(()=>T(()=>function(e,t){e.checked=r(t)?f(t,e.value)>=0:d(e.value,t)}(l,w()??[]))),y(m(l,"input",()=>D(function(e,t){if("radio"===e.type)return e.value;t=s(t);const n=f(t,e.value);return e.checked?n>=0||t.push(e.value):n>=0&&t.splice(n,1),t}(l,w())))),C=!0)}if(!C){const n=p(k,"in")?"in":p(k,"out")?"out":"inout",o=x===_?((e,t)=>{for(;e&&!t(e);)e=(e._x_teleportBack??e).parentElement;return e})(l.parentNode,e=>e._x_dataStack):l;if(!l._x_dataStack)return void a("x-bound directive requires the presence of the x-data directive to bind component properties");if(!o)return void a(`x-bound directive cannot find the parent scope where the '${_}' property is defined`);const r={get:e(g,o,x),set:t(g,o,x)},c={get:e(g,l,_),set:t(g,l,_)};switch(n){case"in":y(v(()=>r.get(),e=>c.set(h(e))));break;case"out":y(v(()=>c.get(),e=>r.set(h(e))));break;default:y(u(r,c))}}function H(e,t){E===e&&(A(),y(m(l,t,A)),C=!0)}})}function x({directive:t,evaluateLater:n,mutateDom:o}){t("format",(t,{modifiers:a},{effect:r})=>{const c=/{{(?<expr>.+?)}}/g,i=p(a,"once"),l=e=>e.hasAttribute("x-format");function u(e){i?o(()=>e()):r(()=>o(()=>e()))}!function a(r){switch(r.nodeType){case Node.TEXT_NODE:!function(t){const a=t.textContent.split(c);if(a.length>1){const r=new DocumentFragment;for(let o=0;a.length>o;o++)if(o%2==0)r.appendChild(document.createTextNode(a[o]));else{const c=e(n,t.parentNode,a[o]),i=document.createTextNode("");r.append(i),u(()=>i.textContent=c())}o(()=>t.parentElement.replaceChild(r,t))}}(r);break;case Node.ELEMENT_NODE:if(r!==t&&(r.hasAttribute("x-data")&&!l(r)&&r.setAttribute("x-format",""),l(r)))break;!function(e){for(let t of e.childNodes)a(t)}(r),function(t){for(let o of t.attributes)if([...o.value.matchAll(c)].length){const a=o.value;u(()=>o.value=a.replace(c,(o,a)=>e(n,t,a)()))}}(r)}}(t)})}function T(e,t,{addScopeToNode:n,cleanup:o,initTree:a,mutateDom:r,scope:c={}}){if(e._r_block)return;document.body._r_block??=(()=>{const e=new MutationObserver(e=>{for(let t of e)for(let e of t.addedNodes)e._r_block?.update()});return e.observe(document.body,{childList:!0,subtree:!0}),e})();let i=l(t)?[...t.content.cloneNode(!0).childNodes]:[t.cloneNode(!0)];r(()=>{for(let t of i)u(t)&&n(t,c,e),e.parentElement.insertBefore(t,e),u(t)&&a(t)}),e._r_block={template:t,update(){r(()=>{for(let t of i??[])e.parentElement.insertBefore(t,e)})},delete(){e._r_block=null;for(let e of i??[])e.remove();i=null}},o(()=>e._r_block?.delete())}function _({addScopeToNode:e,directive:t,initTree:n,mutateDom:o}){t("fragment",(t,{},{cleanup:r})=>{l(t)?T(t,t,{addScopeToNode:e,cleanup:r,initTree:n,mutateDom:o}):a("x-fragment can only be used on a 'template' tag")})}function k({addScopeToNode:t,directive:n,initTree:o,mutateDom:r}){n("match",(n,{},{cleanup:c,effect:i,evaluateLater:u})=>{if(!l(n))return void a("x-match can only be used on a 'template' tag");const s=[];for(let t of n.content.children){const n=t.getAttribute("x-case");null!==n?s.push({el:t,get_value:e(u,n)}):t.hasAttribute("x-default")&&s.push({el:t,get_value:()=>!0,default:!0})}const d=()=>n._r_block?.delete();i(()=>{let e;for(let t of s)t.get_value()&&!e&&(e=t);var a;e?(a=e,n._r_block?.template!==a.el&&(d(),T(n,a.el,{addScopeToNode:t,cleanup:c,initTree:o,mutateDom:r}))):d()})})}function N(e){e.directive("template",(e,{expression:t})=>{if(l(e))return void a("x-template cannot be used on a 'template' tag");const n=document.getElementById(t);l(n)?queueMicrotask(()=>{e.innerHTML="",e.append(n.content.cloneNode(!0))}):a("x-template directive can only reference the template tag")})}function y({addScopeToNode:t,directive:n,initTree:o,mutateDom:r}){n("when",(n,{expression:c},{cleanup:i,effect:u,evaluateLater:s})=>{if(!l(n))return void a("x-when can only be used on a 'template' tag");const d=e(s,c);u(()=>d()?T(n,n,{addScopeToNode:t,cleanup:i,initTree:o,mutateDom:r}):n._r_block?.delete())})}function E(e){g(e),x(e),_(e),k(e),N(e),y(e)}export{g as bound,E as default,x as format,_ as fragment,k as match,N as template,y as when};
1
+ function e(e,...t){const n=e(...t);return()=>{let e;return n(t=>e=t),t=e,"function"==typeof t?.get?e.get():e;var t}}function t(e,...t){const n=e(...t);t[t.length-1]=`${t.at(-1)} = __val`;const o=e(...t);return e=>{let t;n(e=>t=e),function(e){return"function"==typeof e?.set}(t)?t.set(e):o(()=>{},{scope:{__val:e}})}}const n=Symbol();let o;const a=(...e)=>console.warn("alpinegear.js:",...e),r=Array.isArray,c=e=>null==e,i=e=>"checkbox"===e.type||"radio"===e.type,l=e=>e.matches("template"),u=e=>e.nodeType===Node.ELEMENT_NODE,s=e=>r(e)?e:[e],d=(e,t)=>e==t,f=(e,t)=>e.findIndex(e=>e==t),p=(e,t)=>e.includes(t),m=(e,t,n,o)=>(e.addEventListener(t,n,o),()=>e.removeEventListener(t,n,o)),h=e=>"object"==typeof e?JSON.parse(JSON.stringify(e)):e;function v(e,t,n=null){const{effect:o,release:a}=Alpine;let r,c,i,l=!1;const u=o(()=>{r=e(),l||(n?.deep&&JSON.stringify(r),c=r),(l||(n?.immediate??1))&&(i=setTimeout(()=>{t(r,c),c=r})),l=!0});return()=>{clearTimeout(i),a(u)}}const b=new Map("value,checked,files,innerHTML,innerText,textContent,videoHeight,videoWidth,naturalHeight,naturalWidth,clientHeight,clientWidth,offsetHeight,offsetWidth,indeterminate,open,group".split(",").map(e=>[e.trim().toLowerCase(),e.trim()]));function g({directive:l,entangle:u,evaluateLater:g,mapAttributes:x,mutateDom:T,prefixed:_}){x(e=>({name:e.name.replace(/^&/,_("bound:")),value:e.value})),l("bound",(l,{expression:x,value:_,modifiers:k},{effect:N,cleanup:y})=>{if(!_)return void a("x-bound directive expects the presence of a bound property name");const E=l.tagName.toUpperCase();x=x?.trim();const L=b.get(_.trim().replace("-","").toLowerCase());x||=L;const w=e(g,l,x),D=t(g,l,x),S=()=>d(l[L],w())||T(()=>l[L]=w()),A=()=>D((e=>"number"===e.type||"range"===e.type)(l)?function(e){return""===e?null:+e}(l[L]):l[L]);let C;switch(L){case"value":!function(){switch(E){case"INPUT":case"TEXTAREA":c(w())&&A(),N(S),y(m(l,"input",A)),C=!0;break;case"SELECT":setTimeout(()=>{c(w())&&A(),N(()=>function(e,t){for(const n of e.options)n.selected=f(t,n.value)>=0}(l,s(w()??[]))),y(m(l,"change",()=>D(function(e){return e.multiple?[...e.selectedOptions].map(e=>e.value):e.value}(l))))}),C=!0}}();break;case"checked":i(l)&&(N(S),y(m(l,"change",A)),C=!0);break;case"files":"file"===l.type&&(w()instanceof FileList||A(),N(S),y(m(l,"input",A)),C=!0);break;case"innerHTML":case"innerText":case"textContent":l.isContentEditable&&(c(w())&&A(),N(S),y(m(l,"input",A)),C=!0);break;case"videoHeight":case"videoWidth":H("VIDEO","resize");break;case"naturalHeight":case"naturalWidth":H("IMG","load");break;case"clientHeight":case"clientWidth":case"offsetHeight":case"offsetWidth":y(function(e,t){return o??=new ResizeObserver(e=>{for(const t of e)for(const e of t.target[n]?.values()??[])e(t)}),e[n]??=new Set,e[n].add(t),o.observe(e),()=>{e[n].delete(t),e[n].size||(o.unobserve(e),e[n]=null)}}(l,A)),C=!0;break;case"indeterminate":"checkbox"===l.type&&(c(w())&&A(),N(S),y(m(l,"change",A)),C=!0);break;case"open":!function(){const[e,t]=["DETAILS"===E,"DIALOG"===E];(e||t)&&((t||c(w()))&&A(),e&&N(S),y(m(l,"toggle",A)),C=!0)}();break;case"group":i(l)&&(l.name||T(()=>l.name=x),N(()=>T(()=>function(e,t){e.checked=r(t)?f(t,e.value)>=0:d(e.value,t)}(l,w()??[]))),y(m(l,"input",()=>D(function(e,t){if("radio"===e.type)return e.value;t=s(t);const n=f(t,e.value);return e.checked?n>=0||t.push(e.value):n>=0&&t.splice(n,1),t}(l,w())))),C=!0)}if(!C){const n=p(k,"in")?"in":p(k,"out")?"out":"inout",o=x===_?((e,t)=>{for(;e&&!t(e);)e=(e._x_teleportBack??e).parentElement;return e})(l.parentNode,e=>e._x_dataStack):l;if(!l._x_dataStack)return void a("x-bound directive requires the presence of the x-data directive to bind component properties");if(!o)return void a(`x-bound directive cannot find the parent scope where the '${_}' property is defined`);const r={get:e(g,o,x),set:t(g,o,x)},c={get:e(g,l,_),set:t(g,l,_)};switch(n){case"in":y(v(()=>r.get(),e=>c.set(h(e))));break;case"out":y(v(()=>c.get(),e=>r.set(h(e))));break;default:y(u(r,c))}}function H(e,t){E===e&&(A(),y(m(l,t,A)),C=!0)}})}function x({directive:t,evaluateLater:n,mutateDom:o}){t("format",(t,{modifiers:a},{effect:r})=>{const c=p(a,"once"),i=e=>e.hasAttribute("x-format");function l(e){c?o(()=>e()):r(()=>o(()=>e()))}!function a(r){switch(r.nodeType){case Node.TEXT_NODE:!function(t){const a=t.textContent.split(/{{(?<expr>.+?)}}/g);if(a.length>1){const r=new DocumentFragment;for(let o=0;a.length>o;o++)if(o%2==0)r.appendChild(document.createTextNode(a[o]));else{const c=e(n,t.parentNode,a[o]),i=document.createTextNode("");r.append(i),l(()=>i.textContent=c())}o(()=>t.parentElement.replaceChild(r,t))}}(r);break;case Node.ELEMENT_NODE:if(r!==t&&(r.hasAttribute("x-data")&&!i(r)&&r.setAttribute("x-format",""),i(r)))break;!function(e){for(let t of e.childNodes)a(t)}(r),function(t){for(let o of t.attributes){const a=[...o.value.matchAll(/{{(?<expr>.+?)}}/g)];if(a.length){const r=new Map(a.map(o=>[o.groups.expr,e(n,t,o.groups.expr)])),c=o.value;l(()=>o.value=c.replace(/{{(?<expr>.+?)}}/g,(e,t)=>r.get(t)()))}}}(r)}}(t)})}function T(e,t,{addScopeToNode:n,cleanup:o,initTree:a,mutateDom:r,scope:c={}}){if(e._r_block)return;document.body._r_block??=(()=>{const e=new MutationObserver(e=>{for(let t of e)for(let e of t.addedNodes)e._r_block?.update()});return e.observe(document.body,{childList:!0,subtree:!0}),e})();let i=l(t)?[...t.content.cloneNode(!0).childNodes]:[t.cloneNode(!0)];r(()=>{for(let t of i)u(t)&&n(t,c,e),e.parentElement.insertBefore(t,e),u(t)&&a(t)}),e._r_block={template:t,update(){r(()=>{for(let t of i??[])e.parentElement.insertBefore(t,e)})},delete(){e._r_block=null;for(let e of i??[])e.remove();i=null}},o(()=>e._r_block?.delete())}function _({addScopeToNode:e,directive:t,initTree:n,mutateDom:o}){t("fragment",(t,{},{cleanup:r})=>{l(t)?T(t,t,{addScopeToNode:e,cleanup:r,initTree:n,mutateDom:o}):a("x-fragment can only be used on a 'template' tag")})}function k({addScopeToNode:t,directive:n,initTree:o,mutateDom:r}){n("match",(n,{},{cleanup:c,effect:i,evaluateLater:u})=>{if(!l(n))return void a("x-match can only be used on a 'template' tag");const s=[];for(let t of n.content.children){const n=t.getAttribute("x-case");null!==n?s.push({el:t,get_value:e(u,n)}):t.hasAttribute("x-default")&&s.push({el:t,get_value:()=>!0,default:!0})}const d=()=>n._r_block?.delete();i(()=>{let e;for(let t of s)t.get_value()&&!e&&(e=t);var a;e?(a=e,n._r_block?.template!==a.el&&(d(),T(n,a.el,{addScopeToNode:t,cleanup:c,initTree:o,mutateDom:r}))):d()})})}function N(e){e.directive("template",(e,{expression:t})=>{if(l(e))return void a("x-template cannot be used on a 'template' tag");const n=document.getElementById(t);n&&l(n)?queueMicrotask(()=>{e.innerHTML="",e.append(n.content.cloneNode(!0))}):a("x-template directive can only reference the template tag")})}function y({addScopeToNode:t,directive:n,initTree:o,mutateDom:r}){n("when",(n,{expression:c},{cleanup:i,effect:u,evaluateLater:s})=>{if(!l(n))return void a("x-when can only be used on a 'template' tag");const d=e(s,c);u(()=>d()?T(n,n,{addScopeToNode:t,cleanup:i,initTree:o,mutateDom:r}):n._r_block?.delete())})}function E(e){g(e),x(e),_(e),k(e),N(e),y(e)}export{g as bound,E as default,x as format,_ as fragment,k as match,N as template,y as when};
@@ -117,6 +117,7 @@
117
117
  let new_value;
118
118
  let old_value;
119
119
  let initialized = false;
120
+ let timer_id;
120
121
 
121
122
  const handle = effect(() => {
122
123
  new_value = get_value();
@@ -128,7 +129,7 @@
128
129
 
129
130
  if (initialized || (options?.immediate ?? true)) {
130
131
  // Prevent the watcher from detecting its own dependencies.
131
- setTimeout(() => {
132
+ timer_id = setTimeout(() => {
132
133
  callback(new_value, old_value);
133
134
  old_value = new_value;
134
135
  });
@@ -137,7 +138,10 @@
137
138
  initialized = true;
138
139
  });
139
140
 
140
- return () => release(handle);
141
+ return () => {
142
+ clearTimeout(timer_id);
143
+ release(handle);
144
+ }
141
145
  }
142
146
 
143
147
  const canonical_names = create_map(
@@ -451,7 +455,6 @@
451
455
 
452
456
  function plugin$4({ directive, evaluateLater, mutateDom }) {
453
457
  directive("format", (el, { modifiers }, { effect }) => {
454
- const placeholder_regex = /{{(?<expr>.+?)}}/g;
455
458
  const is_once = has_modifier(modifiers, "once");
456
459
  const has_format_attr = el => el.hasAttribute("x-format");
457
460
 
@@ -503,7 +506,7 @@
503
506
  }
504
507
 
505
508
  function process_text_node(node) {
506
- const tokens = node.textContent.split(placeholder_regex);
509
+ const tokens = node.textContent.split(/{{(?<expr>.+?)}}/g);
507
510
 
508
511
  if (tokens.length > 1) {
509
512
  const fragment = new DocumentFragment();
@@ -528,10 +531,19 @@
528
531
 
529
532
  function process_attributes(node) {
530
533
  for (let attr of node.attributes) {
531
- const matches = [...attr.value.matchAll(placeholder_regex)];
534
+ const matches = [...attr.value.matchAll(/{{(?<expr>.+?)}}/g)];
532
535
  if (matches.length) {
536
+ const getters = new Map(
537
+ matches.map(m => [
538
+ m.groups.expr,
539
+ create_getter(
540
+ evaluateLater,
541
+ node,
542
+ m.groups.expr)]));
543
+
533
544
  const template = attr.value;
534
- update(() => attr.value = template.replace(placeholder_regex, (_, expr) => create_getter(evaluateLater, node, expr)()));
545
+
546
+ update(() => attr.value = template.replace(/{{(?<expr>.+?)}}/g, (_, expr) => getters.get(expr)()));
535
547
  }
536
548
  }
537
549
  }
@@ -672,7 +684,7 @@
672
684
 
673
685
  const tpl = document.getElementById(expression);
674
686
 
675
- if (!is_template(tpl)) {
687
+ if (!tpl || !is_template(tpl)) {
676
688
  warn("x-template directive can only reference the template tag");
677
689
  return;
678
690
  }
@@ -1 +1 @@
1
- !function(){"use strict";const e=(...e)=>console.warn("alpinegear.js:",...e),t=Array.isArray,n=e=>null==e,o=e=>"checkbox"===e.type||"radio"===e.type,a=e=>e.matches("template"),i=e=>e.nodeType===Node.ELEMENT_NODE,r=e=>t(e)?e:[e],c=(e,t)=>e==t,l=(e,t)=>e.findIndex(e=>e==t),u=(e,t)=>e.includes(t),s=(e,t,n,o)=>(e.addEventListener(t,n,o),()=>e.removeEventListener(t,n,o)),d=e=>"object"==typeof e?JSON.parse(JSON.stringify(e)):e;function f(e,...t){const n=e(...t);return()=>{let e;return n(t=>e=t),t=e,"function"==typeof t?.get?e.get():e;var t}}function p(e,...t){const n=e(...t);t[t.length-1]=`${t.at(-1)} = __val`;const o=e(...t);return e=>{let t;n(e=>t=e),function(e){return"function"==typeof e?.set}(t)?t.set(e):o(()=>{},{scope:{__val:e}})}}const m=Symbol();let h;function v(e,t,n=null){const{effect:o,release:a}=Alpine;let i,r,c=!1;const l=o(()=>{i=e(),c||(n?.deep&&JSON.stringify(i),r=i),(c||(n?.immediate??1))&&setTimeout(()=>{t(i,r),r=i}),c=!0});return()=>a(l)}const b=new Map("value,checked,files,innerHTML,innerText,textContent,videoHeight,videoWidth,naturalHeight,naturalWidth,clientHeight,clientWidth,offsetHeight,offsetWidth,indeterminate,open,group".split(",").map(e=>[e.trim().toLowerCase(),e.trim()]));function g(e,t,{addScopeToNode:n,cleanup:o,initTree:r,mutateDom:c,scope:l={}}){if(e._r_block)return;document.body._r_block??=(()=>{const e=new MutationObserver(e=>{for(let t of e)for(let e of t.addedNodes)e._r_block?.update()});return e.observe(document.body,{childList:!0,subtree:!0}),e})();let u=a(t)?[...t.content.cloneNode(!0).childNodes]:[t.cloneNode(!0)];c(()=>{for(let t of u)i(t)&&n(t,l,e),e.parentElement.insertBefore(t,e),i(t)&&r(t)}),e._r_block={template:t,update(){c(()=>{for(let t of u??[])e.parentElement.insertBefore(t,e)})},delete(){e._r_block=null;for(let e of u??[])e.remove();u=null}},o(()=>e._r_block?.delete())}function x(i){(function({directive:a,entangle:i,evaluateLater:g,mapAttributes:x,mutateDom:T,prefixed:_}){x(e=>({name:e.name.replace(/^&/,_("bound:")),value:e.value})),a("bound",(a,{expression:x,value:_,modifiers:k},{effect:N,cleanup:y})=>{if(!_)return void e("x-bound directive expects the presence of a bound property name");const E=a.tagName.toUpperCase();x=x?.trim();const L=b.get(_.trim().replace("-","").toLowerCase());x||=L;const D=f(g,a,x),S=p(g,a,x),w=()=>c(a[L],D())||T(()=>a[L]=D()),A=()=>S((e=>"number"===e.type||"range"===e.type)(a)?function(e){return""===e?null:+e}(a[L]):a[L]);let C;switch(L){case"value":!function(){switch(E){case"INPUT":case"TEXTAREA":n(D())&&A(),N(w),y(s(a,"input",A)),C=!0;break;case"SELECT":setTimeout(()=>{n(D())&&A(),N(()=>function(e,t){for(const n of e.options)n.selected=l(t,n.value)>=0}(a,r(D()??[]))),y(s(a,"change",()=>S(function(e){return e.multiple?[...e.selectedOptions].map(e=>e.value):e.value}(a))))}),C=!0}}();break;case"checked":o(a)&&(N(w),y(s(a,"change",A)),C=!0);break;case"files":"file"===a.type&&(D()instanceof FileList||A(),N(w),y(s(a,"input",A)),C=!0);break;case"innerHTML":case"innerText":case"textContent":a.isContentEditable&&(n(D())&&A(),N(w),y(s(a,"input",A)),C=!0);break;case"videoHeight":case"videoWidth":H("VIDEO","resize");break;case"naturalHeight":case"naturalWidth":H("IMG","load");break;case"clientHeight":case"clientWidth":case"offsetHeight":case"offsetWidth":y(function(e,t){return h??=new ResizeObserver(e=>{for(const t of e)for(const e of t.target[m]?.values()??[])e(t)}),e[m]??=new Set,e[m].add(t),h.observe(e),()=>{e[m].delete(t),e[m].size||(h.unobserve(e),e[m]=null)}}(a,A)),C=!0;break;case"indeterminate":"checkbox"===a.type&&(n(D())&&A(),N(w),y(s(a,"change",A)),C=!0);break;case"open":!function(){const[e,t]=["DETAILS"===E,"DIALOG"===E];(e||t)&&((t||n(D()))&&A(),e&&N(w),y(s(a,"toggle",A)),C=!0)}();break;case"group":o(a)&&(a.name||T(()=>a.name=x),N(()=>T(()=>function(e,n){e.checked=t(n)?l(n,e.value)>=0:c(e.value,n)}(a,D()??[]))),y(s(a,"input",()=>S(function(e,t){if("radio"===e.type)return e.value;t=r(t);const n=l(t,e.value);return e.checked?n>=0||t.push(e.value):n>=0&&t.splice(n,1),t}(a,D())))),C=!0)}if(!C){const t=u(k,"in")?"in":u(k,"out")?"out":"inout",n=x===_?((e,t)=>{for(;e&&!t(e);)e=(e._x_teleportBack??e).parentElement;return e})(a.parentNode,e=>e._x_dataStack):a;if(!a._x_dataStack)return void e("x-bound directive requires the presence of the x-data directive to bind component properties");if(!n)return void e(`x-bound directive cannot find the parent scope where the '${_}' property is defined`);const o={get:f(g,n,x),set:p(g,n,x)},r={get:f(g,a,_),set:p(g,a,_)};switch(t){case"in":y(v(()=>o.get(),e=>r.set(d(e))));break;case"out":y(v(()=>r.get(),e=>o.set(d(e))));break;default:y(i(o,r))}}function H(e,t){E===e&&(A(),y(s(a,t,A)),C=!0)}})})(i),function({directive:e,evaluateLater:t,mutateDom:n}){e("format",(e,{modifiers:o},{effect:a})=>{const i=/{{(?<expr>.+?)}}/g,r=u(o,"once"),c=e=>e.hasAttribute("x-format");function l(e){r?n(()=>e()):a(()=>n(()=>e()))}!function o(a){switch(a.nodeType){case Node.TEXT_NODE:!function(e){const o=e.textContent.split(i);if(o.length>1){const a=new DocumentFragment;for(let n=0;o.length>n;n++)if(n%2==0)a.appendChild(document.createTextNode(o[n]));else{const i=f(t,e.parentNode,o[n]),r=document.createTextNode("");a.append(r),l(()=>r.textContent=i())}n(()=>e.parentElement.replaceChild(a,e))}}(a);break;case Node.ELEMENT_NODE:if(a!==e&&(a.hasAttribute("x-data")&&!c(a)&&a.setAttribute("x-format",""),c(a)))break;!function(e){for(let t of e.childNodes)o(t)}(a),function(e){for(let n of e.attributes)if([...n.value.matchAll(i)].length){const o=n.value;l(()=>n.value=o.replace(i,(n,o)=>f(t,e,o)()))}}(a)}}(e)})}(i),function({addScopeToNode:t,directive:n,initTree:o,mutateDom:i}){n("fragment",(n,{},{cleanup:r})=>{a(n)?g(n,n,{addScopeToNode:t,cleanup:r,initTree:o,mutateDom:i}):e("x-fragment can only be used on a 'template' tag")})}(i),function({addScopeToNode:t,directive:n,initTree:o,mutateDom:i}){n("match",(n,{},{cleanup:r,effect:c,evaluateLater:l})=>{if(!a(n))return void e("x-match can only be used on a 'template' tag");const u=[];for(let e of n.content.children){const t=e.getAttribute("x-case");null!==t?u.push({el:e,get_value:f(l,t)}):e.hasAttribute("x-default")&&u.push({el:e,get_value:()=>!0,default:!0})}const s=()=>n._r_block?.delete();c(()=>{let e;for(let t of u)t.get_value()&&!e&&(e=t);var a;e?(a=e,n._r_block?.template!==a.el&&(s(),g(n,a.el,{addScopeToNode:t,cleanup:r,initTree:o,mutateDom:i}))):s()})})}(i),function(t){t.directive("template",(t,{expression:n})=>{if(a(t))return void e("x-template cannot be used on a 'template' tag");const o=document.getElementById(n);a(o)?queueMicrotask(()=>{t.innerHTML="",t.append(o.content.cloneNode(!0))}):e("x-template directive can only reference the template tag")})}(i),function({addScopeToNode:t,directive:n,initTree:o,mutateDom:i}){n("when",(n,{expression:r},{cleanup:c,effect:l,evaluateLater:u})=>{if(!a(n))return void e("x-when can only be used on a 'template' tag");const s=f(u,r);l(()=>s()?g(n,n,{addScopeToNode:t,cleanup:c,initTree:o,mutateDom:i}):n._r_block?.delete())})}(i)}s(document,"alpine:init",()=>Alpine.plugin(x))}();
1
+ !function(){"use strict";const e=(...e)=>console.warn("alpinegear.js:",...e),t=Array.isArray,n=e=>null==e,o=e=>"checkbox"===e.type||"radio"===e.type,a=e=>e.matches("template"),r=e=>e.nodeType===Node.ELEMENT_NODE,i=e=>t(e)?e:[e],c=(e,t)=>e==t,l=(e,t)=>e.findIndex(e=>e==t),u=(e,t)=>e.includes(t),s=(e,t,n,o)=>(e.addEventListener(t,n,o),()=>e.removeEventListener(t,n,o)),d=e=>"object"==typeof e?JSON.parse(JSON.stringify(e)):e;function f(e,...t){const n=e(...t);return()=>{let e;return n(t=>e=t),t=e,"function"==typeof t?.get?e.get():e;var t}}function p(e,...t){const n=e(...t);t[t.length-1]=`${t.at(-1)} = __val`;const o=e(...t);return e=>{let t;n(e=>t=e),function(e){return"function"==typeof e?.set}(t)?t.set(e):o(()=>{},{scope:{__val:e}})}}const m=Symbol();let h;function v(e,t,n=null){const{effect:o,release:a}=Alpine;let r,i,c,l=!1;const u=o(()=>{r=e(),l||(n?.deep&&JSON.stringify(r),i=r),(l||(n?.immediate??1))&&(c=setTimeout(()=>{t(r,i),i=r})),l=!0});return()=>{clearTimeout(c),a(u)}}const b=new Map("value,checked,files,innerHTML,innerText,textContent,videoHeight,videoWidth,naturalHeight,naturalWidth,clientHeight,clientWidth,offsetHeight,offsetWidth,indeterminate,open,group".split(",").map(e=>[e.trim().toLowerCase(),e.trim()]));function g(e,t,{addScopeToNode:n,cleanup:o,initTree:i,mutateDom:c,scope:l={}}){if(e._r_block)return;document.body._r_block??=(()=>{const e=new MutationObserver(e=>{for(let t of e)for(let e of t.addedNodes)e._r_block?.update()});return e.observe(document.body,{childList:!0,subtree:!0}),e})();let u=a(t)?[...t.content.cloneNode(!0).childNodes]:[t.cloneNode(!0)];c(()=>{for(let t of u)r(t)&&n(t,l,e),e.parentElement.insertBefore(t,e),r(t)&&i(t)}),e._r_block={template:t,update(){c(()=>{for(let t of u??[])e.parentElement.insertBefore(t,e)})},delete(){e._r_block=null;for(let e of u??[])e.remove();u=null}},o(()=>e._r_block?.delete())}function x(r){(function({directive:a,entangle:r,evaluateLater:g,mapAttributes:x,mutateDom:T,prefixed:_}){x(e=>({name:e.name.replace(/^&/,_("bound:")),value:e.value})),a("bound",(a,{expression:x,value:_,modifiers:k},{effect:N,cleanup:y})=>{if(!_)return void e("x-bound directive expects the presence of a bound property name");const E=a.tagName.toUpperCase();x=x?.trim();const L=b.get(_.trim().replace("-","").toLowerCase());x||=L;const w=f(g,a,x),D=p(g,a,x),S=()=>c(a[L],w())||T(()=>a[L]=w()),A=()=>D((e=>"number"===e.type||"range"===e.type)(a)?function(e){return""===e?null:+e}(a[L]):a[L]);let C;switch(L){case"value":!function(){switch(E){case"INPUT":case"TEXTAREA":n(w())&&A(),N(S),y(s(a,"input",A)),C=!0;break;case"SELECT":setTimeout(()=>{n(w())&&A(),N(()=>function(e,t){for(const n of e.options)n.selected=l(t,n.value)>=0}(a,i(w()??[]))),y(s(a,"change",()=>D(function(e){return e.multiple?[...e.selectedOptions].map(e=>e.value):e.value}(a))))}),C=!0}}();break;case"checked":o(a)&&(N(S),y(s(a,"change",A)),C=!0);break;case"files":"file"===a.type&&(w()instanceof FileList||A(),N(S),y(s(a,"input",A)),C=!0);break;case"innerHTML":case"innerText":case"textContent":a.isContentEditable&&(n(w())&&A(),N(S),y(s(a,"input",A)),C=!0);break;case"videoHeight":case"videoWidth":H("VIDEO","resize");break;case"naturalHeight":case"naturalWidth":H("IMG","load");break;case"clientHeight":case"clientWidth":case"offsetHeight":case"offsetWidth":y(function(e,t){return h??=new ResizeObserver(e=>{for(const t of e)for(const e of t.target[m]?.values()??[])e(t)}),e[m]??=new Set,e[m].add(t),h.observe(e),()=>{e[m].delete(t),e[m].size||(h.unobserve(e),e[m]=null)}}(a,A)),C=!0;break;case"indeterminate":"checkbox"===a.type&&(n(w())&&A(),N(S),y(s(a,"change",A)),C=!0);break;case"open":!function(){const[e,t]=["DETAILS"===E,"DIALOG"===E];(e||t)&&((t||n(w()))&&A(),e&&N(S),y(s(a,"toggle",A)),C=!0)}();break;case"group":o(a)&&(a.name||T(()=>a.name=x),N(()=>T(()=>function(e,n){e.checked=t(n)?l(n,e.value)>=0:c(e.value,n)}(a,w()??[]))),y(s(a,"input",()=>D(function(e,t){if("radio"===e.type)return e.value;t=i(t);const n=l(t,e.value);return e.checked?n>=0||t.push(e.value):n>=0&&t.splice(n,1),t}(a,w())))),C=!0)}if(!C){const t=u(k,"in")?"in":u(k,"out")?"out":"inout",n=x===_?((e,t)=>{for(;e&&!t(e);)e=(e._x_teleportBack??e).parentElement;return e})(a.parentNode,e=>e._x_dataStack):a;if(!a._x_dataStack)return void e("x-bound directive requires the presence of the x-data directive to bind component properties");if(!n)return void e(`x-bound directive cannot find the parent scope where the '${_}' property is defined`);const o={get:f(g,n,x),set:p(g,n,x)},i={get:f(g,a,_),set:p(g,a,_)};switch(t){case"in":y(v(()=>o.get(),e=>i.set(d(e))));break;case"out":y(v(()=>i.get(),e=>o.set(d(e))));break;default:y(r(o,i))}}function H(e,t){E===e&&(A(),y(s(a,t,A)),C=!0)}})})(r),function({directive:e,evaluateLater:t,mutateDom:n}){e("format",(e,{modifiers:o},{effect:a})=>{const r=u(o,"once"),i=e=>e.hasAttribute("x-format");function c(e){r?n(()=>e()):a(()=>n(()=>e()))}!function o(a){switch(a.nodeType){case Node.TEXT_NODE:!function(e){const o=e.textContent.split(/{{(?<expr>.+?)}}/g);if(o.length>1){const a=new DocumentFragment;for(let n=0;o.length>n;n++)if(n%2==0)a.appendChild(document.createTextNode(o[n]));else{const r=f(t,e.parentNode,o[n]),i=document.createTextNode("");a.append(i),c(()=>i.textContent=r())}n(()=>e.parentElement.replaceChild(a,e))}}(a);break;case Node.ELEMENT_NODE:if(a!==e&&(a.hasAttribute("x-data")&&!i(a)&&a.setAttribute("x-format",""),i(a)))break;!function(e){for(let t of e.childNodes)o(t)}(a),function(e){for(let n of e.attributes){const o=[...n.value.matchAll(/{{(?<expr>.+?)}}/g)];if(o.length){const a=new Map(o.map(n=>[n.groups.expr,f(t,e,n.groups.expr)])),r=n.value;c(()=>n.value=r.replace(/{{(?<expr>.+?)}}/g,(e,t)=>a.get(t)()))}}}(a)}}(e)})}(r),function({addScopeToNode:t,directive:n,initTree:o,mutateDom:r}){n("fragment",(n,{},{cleanup:i})=>{a(n)?g(n,n,{addScopeToNode:t,cleanup:i,initTree:o,mutateDom:r}):e("x-fragment can only be used on a 'template' tag")})}(r),function({addScopeToNode:t,directive:n,initTree:o,mutateDom:r}){n("match",(n,{},{cleanup:i,effect:c,evaluateLater:l})=>{if(!a(n))return void e("x-match can only be used on a 'template' tag");const u=[];for(let e of n.content.children){const t=e.getAttribute("x-case");null!==t?u.push({el:e,get_value:f(l,t)}):e.hasAttribute("x-default")&&u.push({el:e,get_value:()=>!0,default:!0})}const s=()=>n._r_block?.delete();c(()=>{let e;for(let t of u)t.get_value()&&!e&&(e=t);var a;e?(a=e,n._r_block?.template!==a.el&&(s(),g(n,a.el,{addScopeToNode:t,cleanup:i,initTree:o,mutateDom:r}))):s()})})}(r),function(t){t.directive("template",(t,{expression:n})=>{if(a(t))return void e("x-template cannot be used on a 'template' tag");const o=document.getElementById(n);o&&a(o)?queueMicrotask(()=>{t.innerHTML="",t.append(o.content.cloneNode(!0))}):e("x-template directive can only reference the template tag")})}(r),function({addScopeToNode:t,directive:n,initTree:o,mutateDom:r}){n("when",(n,{expression:i},{cleanup:c,effect:l,evaluateLater:u})=>{if(!a(n))return void e("x-when can only be used on a 'template' tag");const s=f(u,i);l(()=>s()?g(n,n,{addScopeToNode:t,cleanup:c,initTree:o,mutateDom:r}):n._r_block?.delete())})}(r)}s(document,"alpine:init",()=>Alpine.plugin(x))}();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ramstack/alpinegear-main",
3
- "version": "1.4.4",
3
+ "version": "1.4.5",
4
4
  "description": "@ramstack/alpinegear-main is a combined plugin that includes several Alpine.js directives, providing a convenient all-in-one package.",
5
5
  "author": "Rameel Burhan",
6
6
  "license": "MIT",