@ramstack/alpinegear-match 1.0.0 → 1.1.0-preview.2

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.
@@ -73,7 +73,7 @@ function has_getter(value) {
73
73
  function plugin({ addScopeToNode, directive, initTree, mutateDom }) {
74
74
  directive("match", (el, { }, { cleanup, effect, evaluateLater }) => {
75
75
  if (!is_template(el)) {
76
- warn("x-match can only be used on a 'template' tag.");
76
+ warn("x-match can only be used on a 'template' tag");
77
77
  return;
78
78
  }
79
79
 
@@ -83,15 +83,15 @@ function plugin({ addScopeToNode, directive, initTree, mutateDom }) {
83
83
  for (let node of el.content.children) {
84
84
  const expr = node.getAttribute("x-case");
85
85
  if (expr !== null) {
86
- has_default_case() && warn("The x-case directive cannot be appear after x-default.");
86
+ has_default_case() && warn("The x-case directive cannot be appear after x-default");
87
87
  branches.push({ el: node, get_value: create_getter(evaluateLater, expr) });
88
88
  }
89
89
  else if (node.hasAttribute("x-default")) {
90
- has_default_case() && warn("Only one x-default directive is allowed.");
90
+ has_default_case() && warn("Only one x-default directive is allowed");
91
91
  branches.push({ el: node, get_value: () => true, default: true });
92
92
  }
93
93
  else {
94
- warn("Element has no x-case or x-default directive and will be ignored.", node);
94
+ warn("Element has no x-case or x-default directive and will be ignored", node);
95
95
  }
96
96
  }
97
97
 
@@ -1 +1 @@
1
- const e=e=>e instanceof HTMLTemplateElement,t=e=>e.nodeType===Node.ELEMENT_NODE;function o(e,...t){const o=e(...t);return()=>{let e;return o((t=>e=t)),t=e,"function"==typeof t?.get?e.get():e;var t}}function l({addScopeToNode:l,directive:n,initTree:r,mutateDom:c}){n("match",((n,{},{cleanup:a,effect:d,evaluateLater:u})=>{if(!e(n))return void console.warn("alpine-gear.js:","x-match can only be used on a 'template' tag.");const f=[];for(let e of n.content.children){const t=e.getAttribute("x-case");null!==t?f.push({el:e,get_value:o(u,t)}):e.hasAttribute("x-default")&&f.push({el:e,get_value:()=>!0,default:!0})}const i=()=>n._r_block?.delete();d((()=>{let o;for(let e of f)e.get_value()&&!o&&(o=e);var d;o?(d=o,n._r_block?.template!==d.el&&(i(),function(o,l,{addScopeToNode:n,cleanup:r,initTree:c,mutateDom:a,scope:d={}}){if(o._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=e(l)?[...l.content.cloneNode(!0).childNodes]:[l.cloneNode(!0)];a((()=>{for(let e of u)t(e)&&n(e,d,o),o.parentElement.insertBefore(e,o),t(e)&&c(e)})),o._r_block={template:l,update(){a((()=>{for(let e of u??[])o.parentElement.insertBefore(e,o)}))},delete(){o._r_block=null;for(let e of u??[])e.remove();u=null}},r((()=>o._r_block?.delete()))}(n,d.el,{addScopeToNode:l,cleanup:a,initTree:r,mutateDom:c}))):i()}))}))}export{l as match};
1
+ const e=e=>e instanceof HTMLTemplateElement,t=e=>e.nodeType===Node.ELEMENT_NODE;function o(e,...t){const o=e(...t);return()=>{let e;return o((t=>e=t)),t=e,"function"==typeof t?.get?e.get():e;var t}}function l({addScopeToNode:l,directive:n,initTree:r,mutateDom:c}){n("match",((n,{},{cleanup:a,effect:d,evaluateLater:u})=>{if(!e(n))return void console.warn("alpine-gear.js:","x-match can only be used on a 'template' tag");const f=[];for(let e of n.content.children){const t=e.getAttribute("x-case");null!==t?f.push({el:e,get_value:o(u,t)}):e.hasAttribute("x-default")&&f.push({el:e,get_value:()=>!0,default:!0})}const i=()=>n._r_block?.delete();d((()=>{let o;for(let e of f)e.get_value()&&!o&&(o=e);var d;o?(d=o,n._r_block?.template!==d.el&&(i(),function(o,l,{addScopeToNode:n,cleanup:r,initTree:c,mutateDom:a,scope:d={}}){if(o._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=e(l)?[...l.content.cloneNode(!0).childNodes]:[l.cloneNode(!0)];a((()=>{for(let e of u)t(e)&&n(e,d,o),o.parentElement.insertBefore(e,o),t(e)&&c(e)})),o._r_block={template:l,update(){a((()=>{for(let e of u??[])o.parentElement.insertBefore(e,o)}))},delete(){o._r_block=null;for(let e of u??[])e.remove();u=null}},r((()=>o._r_block?.delete()))}(n,d.el,{addScopeToNode:l,cleanup:a,initTree:r,mutateDom:c}))):i()}))}))}export{l as match};
@@ -76,7 +76,7 @@
76
76
  function plugin({ addScopeToNode, directive, initTree, mutateDom }) {
77
77
  directive("match", (el, { }, { cleanup, effect, evaluateLater }) => {
78
78
  if (!is_template(el)) {
79
- warn("x-match can only be used on a 'template' tag.");
79
+ warn("x-match can only be used on a 'template' tag");
80
80
  return;
81
81
  }
82
82
 
@@ -86,15 +86,15 @@
86
86
  for (let node of el.content.children) {
87
87
  const expr = node.getAttribute("x-case");
88
88
  if (expr !== null) {
89
- has_default_case() && warn("The x-case directive cannot be appear after x-default.");
89
+ has_default_case() && warn("The x-case directive cannot be appear after x-default");
90
90
  branches.push({ el: node, get_value: create_getter(evaluateLater, expr) });
91
91
  }
92
92
  else if (node.hasAttribute("x-default")) {
93
- has_default_case() && warn("Only one x-default directive is allowed.");
93
+ has_default_case() && warn("Only one x-default directive is allowed");
94
94
  branches.push({ el: node, get_value: () => true, default: true });
95
95
  }
96
96
  else {
97
- warn("Element has no x-case or x-default directive and will be ignored.", node);
97
+ warn("Element has no x-case or x-default directive and will be ignored", node);
98
98
  }
99
99
  }
100
100
 
@@ -1 +1 @@
1
- !function(){"use strict";const e=e=>e instanceof HTMLTemplateElement,t=e=>e.nodeType===Node.ELEMENT_NODE;function o(e,...t){const o=e(...t);return()=>{let e;return o((t=>e=t)),t=e,"function"==typeof t?.get?e.get():e;var t}}function n({addScopeToNode:n,directive:l,initTree:r,mutateDom:c}){l("match",((l,{},{cleanup:a,effect:u,evaluateLater:d})=>{if(!e(l))return void console.warn("alpine-gear.js:","x-match can only be used on a 'template' tag.");const i=[];for(let e of l.content.children){const t=e.getAttribute("x-case");null!==t?i.push({el:e,get_value:o(d,t)}):e.hasAttribute("x-default")&&i.push({el:e,get_value:()=>!0,default:!0})}const f=()=>l._r_block?.delete();u((()=>{let o;for(let e of i)e.get_value()&&!o&&(o=e);var u;o?(u=o,l._r_block?.template!==u.el&&(f(),function(o,n,{addScopeToNode:l,cleanup:r,initTree:c,mutateDom:a,scope:u={}}){if(o._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 d=e(n)?[...n.content.cloneNode(!0).childNodes]:[n.cloneNode(!0)];a((()=>{for(let e of d)t(e)&&l(e,u,o),o.parentElement.insertBefore(e,o),t(e)&&c(e)})),o._r_block={template:n,update(){a((()=>{for(let e of d??[])o.parentElement.insertBefore(e,o)}))},delete(){o._r_block=null;for(let e of d??[])e.remove();d=null}},r((()=>o._r_block?.delete()))}(l,u.el,{addScopeToNode:n,cleanup:a,initTree:r,mutateDom:c}))):f()}))}))}document.addEventListener("alpine:init",(()=>{Alpine.plugin(n)}))}();
1
+ !function(){"use strict";const e=e=>e instanceof HTMLTemplateElement,t=e=>e.nodeType===Node.ELEMENT_NODE;function o(e,...t){const o=e(...t);return()=>{let e;return o((t=>e=t)),t=e,"function"==typeof t?.get?e.get():e;var t}}function n({addScopeToNode:n,directive:l,initTree:r,mutateDom:c}){l("match",((l,{},{cleanup:a,effect:u,evaluateLater:d})=>{if(!e(l))return void console.warn("alpine-gear.js:","x-match can only be used on a 'template' tag");const i=[];for(let e of l.content.children){const t=e.getAttribute("x-case");null!==t?i.push({el:e,get_value:o(d,t)}):e.hasAttribute("x-default")&&i.push({el:e,get_value:()=>!0,default:!0})}const f=()=>l._r_block?.delete();u((()=>{let o;for(let e of i)e.get_value()&&!o&&(o=e);var u;o?(u=o,l._r_block?.template!==u.el&&(f(),function(o,n,{addScopeToNode:l,cleanup:r,initTree:c,mutateDom:a,scope:u={}}){if(o._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 d=e(n)?[...n.content.cloneNode(!0).childNodes]:[n.cloneNode(!0)];a((()=>{for(let e of d)t(e)&&l(e,u,o),o.parentElement.insertBefore(e,o),t(e)&&c(e)})),o._r_block={template:n,update(){a((()=>{for(let e of d??[])o.parentElement.insertBefore(e,o)}))},delete(){o._r_block=null;for(let e of d??[])e.remove();d=null}},r((()=>o._r_block?.delete()))}(l,u.el,{addScopeToNode:n,cleanup:a,initTree:r,mutateDom:c}))):f()}))}))}document.addEventListener("alpine:init",(()=>{Alpine.plugin(n)}))}();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ramstack/alpinegear-match",
3
- "version": "1.0.0",
3
+ "version": "1.1.0-preview.2",
4
4
  "description": "@ramstack/alpinegear-match provides the 'x-match' Alpine.js directive, which functions similarly to the 'switch' statement in many programming languages, allowing to conditionally render elements based on matching cases.",
5
5
  "author": "Rameel Burhan",
6
6
  "license": "MIT",