@ramstack/alpinegear-main 1.2.2 → 1.2.4
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.
- package/README.md +36 -1
- package/alpinegear-main.esm.js +1 -0
- package/alpinegear-main.esm.min.js +1 -1
- package/alpinegear-main.js +1 -0
- package/alpinegear-main.min.js +1 -1
- package/package.json +8 -2
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@ To include the CDN version of this plugin, add the following `<script>` tag befo
|
|
|
14
14
|
<script src="https://cdn.jsdelivr.net/npm/@ramstack/alpinegear-main@1/alpinegear-main.min.js" defer></script>
|
|
15
15
|
|
|
16
16
|
<!-- alpine.js -->
|
|
17
|
-
<script src="https://cdn.jsdelivr.net/npm/alpinejs@3
|
|
17
|
+
<script src="https://cdn.jsdelivr.net/npm/alpinejs@3/dist/cdn.min.js" defer></script>
|
|
18
18
|
```
|
|
19
19
|
|
|
20
20
|
### Using NPM
|
|
@@ -139,6 +139,41 @@ You can find the source code for this plugin on GitHub:
|
|
|
139
139
|
|
|
140
140
|
https://github.com/rameel/ramstack.alpinegear.js/tree/main/src/plugins/main
|
|
141
141
|
|
|
142
|
+
## Related projects
|
|
143
|
+
|
|
144
|
+
**[@ramstack/alpinegear-bound](https://www.npmjs.com/package/@ramstack/alpinegear-bound)** ([README](https://github.com/rameel/ramstack.alpinegear.js/tree/main/src/plugins/bound))<br>
|
|
145
|
+
Provides the `x-bound` directive, which allows for two-way binding of input elements and their associated data properties.
|
|
146
|
+
It works similarly to the binding provided by [Svelte](https://svelte.dev/docs/element-directives#bind-property)
|
|
147
|
+
and also supports synchronizing values between two `Alpine.js` data properties.
|
|
148
|
+
|
|
149
|
+
**[@ramstack/alpinegear-format](https://www.npmjs.com/package/@ramstack/alpinegear-format)** ([README](https://github.com/rameel/ramstack.alpinegear.js/tree/main/src/plugins/format))<br>
|
|
150
|
+
Provides the `x-format` directive, which allows you to easily interpolate text using a template syntax similar to what's available in `Vue.js`.
|
|
151
|
+
|
|
152
|
+
**[@ramstack/alpinegear-template](https://www.npmjs.com/package/@ramstack/alpinegear-template)** ([README](https://github.com/rameel/ramstack.alpinegear.js/tree/main/src/plugins/template))<br>
|
|
153
|
+
Provides the `x-template` directive, which allows you to define a template once anywhere in the DOM and reference it by its ID.
|
|
154
|
+
|
|
155
|
+
**[@ramstack/alpinegear-fragment](https://www.npmjs.com/package/@ramstack/alpinegear-fragment)** ([README](https://github.com/rameel/ramstack.alpinegear.js/tree/main/src/plugins/fragment))<br>
|
|
156
|
+
Provides the `x-fragment` directive, which allows for fragment-like behavior similar to what's available in frameworks
|
|
157
|
+
like `Vue.js` or `React`, where multiple root elements can be grouped together.
|
|
158
|
+
|
|
159
|
+
**[@ramstack/alpinegear-match](https://www.npmjs.com/package/@ramstack/alpinegear-match)** ([README](https://github.com/rameel/ramstack.alpinegear.js/tree/main/src/plugins/match))<br>
|
|
160
|
+
Provides the `x-match` directive, which functions similarly to the `switch` statement in many programming languages,
|
|
161
|
+
allowing you to conditionally render elements based on matching cases.
|
|
162
|
+
|
|
163
|
+
**[@ramstack/alpinegear-when](https://www.npmjs.com/package/@ramstack/alpinegear-when)** ([README](https://github.com/rameel/ramstack.alpinegear.js/tree/main/src/plugins/when))<br>
|
|
164
|
+
Provides the `x-when` directive, which allows for conditional rendering of elements similar to `x-if`, but supports multiple root elements.
|
|
165
|
+
|
|
166
|
+
**[@ramstack/alpinegear-destroy](https://www.npmjs.com/package/@ramstack/alpinegear-destroy)** ([README](https://github.com/rameel/ramstack.alpinegear.js/tree/main/src/plugins/destroy))<br>
|
|
167
|
+
Provides the `x-destroy` directive, which is the opposite of `x-init` and allows you to hook into the cleanup phase
|
|
168
|
+
of any element, running a callback when the element is removed from the DOM.
|
|
169
|
+
|
|
170
|
+
**[@ramstack/alpinegear-hotkey](https://www.npmjs.com/package/@ramstack/alpinegear-hotkey)** ([README](https://github.com/rameel/ramstack.alpinegear.js/tree/main/src/plugins/hotkey))<br>
|
|
171
|
+
Provides the `x-hotkey` directive, which allows you to easily handle keyboard shortcuts within your Alpine.js components or application.
|
|
172
|
+
|
|
173
|
+
**[@ramstack/alpinegear-router](https://www.npmjs.com/package/@ramstack/alpinegear-router)** ([README](https://github.com/rameel/ramstack.alpinegear.js/tree/main/src/plugins/router))<br>
|
|
174
|
+
Provides the `x-router` and `x-route` directives, which enable client-side navigation and routing functionality within your Alpine.js application.
|
|
175
|
+
|
|
176
|
+
|
|
142
177
|
## Contributions
|
|
143
178
|
Bug reports and contributions are welcome.
|
|
144
179
|
|
package/alpinegear-main.esm.js
CHANGED
|
@@ -323,6 +323,7 @@ function plugin$5({ directive, entangle, evaluateLater, mapAttributes, mutateDom
|
|
|
323
323
|
if (el.type === "checkbox") {
|
|
324
324
|
is_nullish(get_value()) && update_variable();
|
|
325
325
|
effect(update_property);
|
|
326
|
+
cleanup(listen(el, "change", update_variable));
|
|
326
327
|
processed = true;
|
|
327
328
|
}
|
|
328
329
|
}
|
|
@@ -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,
|
|
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 instanceof HTMLTemplateElement,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},0),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:T,mutateDom:x,prefixed:_}){T(e=>({name:e.name.replace(/^&/,_("bound:")),value:e.value})),l("bound",(l,{expression:T,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();T=T?.trim();const L=b.get(_.trim().replace("-","").toLowerCase());T||=L;const w=e(g,l,T),S=t(g,l,T),D=()=>d(l[L],w())||x(()=>l[L]=w()),A=()=>S((e=>"number"===e.type||"range"===e.type)(l)?function(e){return""===e?null:+e}(l[L]):l[L]);let H;switch(L){case"value":!function(){switch(E){case"INPUT":case"TEXTAREA":c(w())&&A(),N(D),y(m(l,"input",A)),H=!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",()=>S(function(e){return e.multiple?[...e.selectedOptions].map(e=>e.value):e.value}(l))))},0),H=!0}}();break;case"checked":i(l)&&(N(D),y(m(l,"change",A)),H=!0);break;case"files":"file"===l.type&&(w()instanceof FileList||A(),N(D),y(m(l,"input",A)),H=!0);break;case"innerHTML":case"innerText":case"textContent":"true"===l.contentEditable&&(c(w())&&A(),N(D),y(m(l,"input",A)),H=!0);break;case"videoHeight":case"videoWidth":C("VIDEO","resize");break;case"naturalHeight":case"naturalWidth":C("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)),H=!0;break;case"indeterminate":"checkbox"===l.type&&(c(w())&&A(),N(D),y(m(l,"change",A)),H=!0);break;case"open":"DETAILS"===E&&(c(w())&&A(),N(D),y(m(l,"toggle",A)),H=!0);break;case"group":i(l)&&(l.name||x(()=>l.name=T),N(()=>x(()=>function(e,t){e.checked=r(t)?f(t,e.value)>=0:d(e.value,t)}(l,w()??[]))),y(m(l,"input",()=>S(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())))),H=!0)}if(!H){const n=p(k,"in")?"in":p(k,"out")?"out":"inout",o=T===_?((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,T),set:t(g,o,T)},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 C(e,t){E===e&&(A(),y(m(l,t,A)),H=!0)}})}function T({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 x(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)?x(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(),x(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()?x(n,n,{addScopeToNode:t,cleanup:i,initTree:o,mutateDom:r}):n._r_block?.delete())})}export{g as bound,T as format,_ as fragment,k as match,N as template,y as when};
|
package/alpinegear-main.js
CHANGED
package/alpinegear-main.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(){"use strict";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),i=Array.isArray,r=e=>null==e,c=e=>"checkbox"===e.type||"radio"===e.type,l=e=>e instanceof HTMLTemplateElement,u=e=>e.nodeType===Node.ELEMENT_NODE,s=e=>i(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)),v=e=>"object"==typeof e?JSON.parse(JSON.stringify(e)):e;function h(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},0),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:a,mutateDom:i,scope:r={}}){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 c=l(t)?[...t.content.cloneNode(!0).childNodes]:[t.cloneNode(!0)];i(()=>{for(let t of c)u(t)&&n(t,r,e),e.parentElement.insertBefore(t,e),u(t)&&a(t)}),e._r_block={template:t,update(){i(()=>{for(let t of c??[])e.parentElement.insertBefore(t,e)})},delete(){e._r_block=null;for(let e of c??[])e.remove();c=null}},o(()=>e._r_block?.delete())}function T(u){(function({directive:l,entangle:u,evaluateLater:g,mapAttributes:T,mutateDom:x,prefixed:_}){T(e=>({name:e.name.replace(/^&/,_("bound:")),value:e.value})),l("bound",(l,{expression:T,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();T=T?.trim();const L=b.get(_.trim().replace("-","").toLowerCase());T||=L;const S=e(g,l,T),w=t(g,l,T),D=()=>d(l[L],S())||x(()=>l[L]=S()),A=()=>w((e=>"number"===e.type||"range"===e.type)(l)?function(e){return""===e?null:+e}(l[L]):l[L]);let H;switch(L){case"value":!function(){switch(E){case"INPUT":case"TEXTAREA":r(S())&&A(),N(D),y(m(l,"input",A)),H=!0;break;case"SELECT":setTimeout(()=>{r(S())&&A(),N(()=>function(e,t){for(const n of e.options)n.selected=f(t,n.value)>=0}(l,s(S()??[]))),y(m(l,"change",()=>w(function(e){return e.multiple?[...e.selectedOptions].map(e=>e.value):e.value}(l))))},0),H=!0}}();break;case"checked":c(l)&&(N(D),y(m(l,"change",A)),H=!0);break;case"files":"file"===l.type&&(S()instanceof FileList||A(),N(D),y(m(l,"input",A)),H=!0);break;case"innerHTML":case"innerText":case"textContent":"true"===l.contentEditable&&(r(S())&&A(),N(D),y(m(l,"input",A)),H=!0);break;case"videoHeight":case"videoWidth":C("VIDEO","resize");break;case"naturalHeight":case"naturalWidth":C("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)),H=!0;break;case"indeterminate":"checkbox"===l.type&&(r(S())&&A(),N(D),H=!0);break;case"open":"DETAILS"===E&&(r(S())&&A(),N(D),y(m(l,"toggle",A)),H=!0);break;case"group":c(l)&&(l.name||x(()=>l.name=T),N(()=>x(()=>function(e,t){e.checked=i(t)?f(t,e.value)>=0:d(e.value,t)}(l,S()??[]))),y(m(l,"input",()=>w(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,S())))),H=!0)}if(!H){const n=p(k,"in")?"in":p(k,"out")?"out":"inout",o=T===_?((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 i={get:e(g,o,T),set:t(g,o,T)},r={get:e(g,l,_),set:t(g,l,_)};switch(n){case"in":y(h(()=>i.get(),e=>r.set(v(e))));break;case"out":y(h(()=>r.get(),e=>i.set(v(e))));break;default:y(u(i,r))}}function C(e,t){E===e&&(A(),y(m(l,t,A)),H=!0)}})})(u),function({directive:t,evaluateLater:n,mutateDom:o}){t("format",(t,{modifiers:a},{effect:i})=>{const r=/{{(?<expr>.+?)}}/g,c=p(a,"once"),l=e=>e.hasAttribute("x-format");function u(e){c?o(()=>e()):i(()=>o(()=>e()))}!function a(i){switch(i.nodeType){case Node.TEXT_NODE:!function(t){const a=t.textContent.split(r);if(a.length>1){const i=new DocumentFragment;for(let o=0;a.length>o;o++)if(o%2==0)i.appendChild(document.createTextNode(a[o]));else{const r=e(n,t.parentNode,a[o]),c=document.createTextNode("");i.append(c),u(()=>c.textContent=r())}o(()=>t.parentElement.replaceChild(i,t))}}(i);break;case Node.ELEMENT_NODE:if(i!==t&&(i.hasAttribute("x-data")&&!l(i)&&i.setAttribute("x-format",""),l(i)))break;!function(e){for(let t of e.childNodes)a(t)}(i),function(t){for(let o of t.attributes)if([...o.value.matchAll(r)].length){const a=o.value;u(()=>o.value=a.replace(r,(o,a)=>e(n,t,a)()))}}(i)}}(t)})}(u),function({addScopeToNode:e,directive:t,initTree:n,mutateDom:o}){t("fragment",(t,{},{cleanup:i})=>{l(t)?g(t,t,{addScopeToNode:e,cleanup:i,initTree:n,mutateDom:o}):a("x-fragment can only be used on a 'template' tag")})}(u),function({addScopeToNode:t,directive:n,initTree:o,mutateDom:i}){n("match",(n,{},{cleanup:r,effect:c,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();c(()=>{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(),g(n,a.el,{addScopeToNode:t,cleanup:r,initTree:o,mutateDom:i}))):d()})})}(u),function(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")})}(u),function({addScopeToNode:t,directive:n,initTree:o,mutateDom:i}){n("when",(n,{expression:r},{cleanup:c,effect:u,evaluateLater:s})=>{if(!l(n))return void a("x-when can only be used on a 'template' tag");const d=e(s,r);u(()=>d()?g(n,n,{addScopeToNode:t,cleanup:c,initTree:o,mutateDom:i}):n._r_block?.delete())})}(u)}document.addEventListener("alpine:init",()=>{Alpine.plugin(T)})}();
|
|
1
|
+
!function(){"use strict";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),i=Array.isArray,r=e=>null==e,c=e=>"checkbox"===e.type||"radio"===e.type,l=e=>e instanceof HTMLTemplateElement,u=e=>e.nodeType===Node.ELEMENT_NODE,s=e=>i(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)),v=e=>"object"==typeof e?JSON.parse(JSON.stringify(e)):e;function h(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},0),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:a,mutateDom:i,scope:r={}}){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 c=l(t)?[...t.content.cloneNode(!0).childNodes]:[t.cloneNode(!0)];i(()=>{for(let t of c)u(t)&&n(t,r,e),e.parentElement.insertBefore(t,e),u(t)&&a(t)}),e._r_block={template:t,update(){i(()=>{for(let t of c??[])e.parentElement.insertBefore(t,e)})},delete(){e._r_block=null;for(let e of c??[])e.remove();c=null}},o(()=>e._r_block?.delete())}function T(u){(function({directive:l,entangle:u,evaluateLater:g,mapAttributes:T,mutateDom:x,prefixed:_}){T(e=>({name:e.name.replace(/^&/,_("bound:")),value:e.value})),l("bound",(l,{expression:T,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();T=T?.trim();const L=b.get(_.trim().replace("-","").toLowerCase());T||=L;const S=e(g,l,T),w=t(g,l,T),D=()=>d(l[L],S())||x(()=>l[L]=S()),A=()=>w((e=>"number"===e.type||"range"===e.type)(l)?function(e){return""===e?null:+e}(l[L]):l[L]);let H;switch(L){case"value":!function(){switch(E){case"INPUT":case"TEXTAREA":r(S())&&A(),N(D),y(m(l,"input",A)),H=!0;break;case"SELECT":setTimeout(()=>{r(S())&&A(),N(()=>function(e,t){for(const n of e.options)n.selected=f(t,n.value)>=0}(l,s(S()??[]))),y(m(l,"change",()=>w(function(e){return e.multiple?[...e.selectedOptions].map(e=>e.value):e.value}(l))))},0),H=!0}}();break;case"checked":c(l)&&(N(D),y(m(l,"change",A)),H=!0);break;case"files":"file"===l.type&&(S()instanceof FileList||A(),N(D),y(m(l,"input",A)),H=!0);break;case"innerHTML":case"innerText":case"textContent":"true"===l.contentEditable&&(r(S())&&A(),N(D),y(m(l,"input",A)),H=!0);break;case"videoHeight":case"videoWidth":C("VIDEO","resize");break;case"naturalHeight":case"naturalWidth":C("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)),H=!0;break;case"indeterminate":"checkbox"===l.type&&(r(S())&&A(),N(D),y(m(l,"change",A)),H=!0);break;case"open":"DETAILS"===E&&(r(S())&&A(),N(D),y(m(l,"toggle",A)),H=!0);break;case"group":c(l)&&(l.name||x(()=>l.name=T),N(()=>x(()=>function(e,t){e.checked=i(t)?f(t,e.value)>=0:d(e.value,t)}(l,S()??[]))),y(m(l,"input",()=>w(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,S())))),H=!0)}if(!H){const n=p(k,"in")?"in":p(k,"out")?"out":"inout",o=T===_?((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 i={get:e(g,o,T),set:t(g,o,T)},r={get:e(g,l,_),set:t(g,l,_)};switch(n){case"in":y(h(()=>i.get(),e=>r.set(v(e))));break;case"out":y(h(()=>r.get(),e=>i.set(v(e))));break;default:y(u(i,r))}}function C(e,t){E===e&&(A(),y(m(l,t,A)),H=!0)}})})(u),function({directive:t,evaluateLater:n,mutateDom:o}){t("format",(t,{modifiers:a},{effect:i})=>{const r=/{{(?<expr>.+?)}}/g,c=p(a,"once"),l=e=>e.hasAttribute("x-format");function u(e){c?o(()=>e()):i(()=>o(()=>e()))}!function a(i){switch(i.nodeType){case Node.TEXT_NODE:!function(t){const a=t.textContent.split(r);if(a.length>1){const i=new DocumentFragment;for(let o=0;a.length>o;o++)if(o%2==0)i.appendChild(document.createTextNode(a[o]));else{const r=e(n,t.parentNode,a[o]),c=document.createTextNode("");i.append(c),u(()=>c.textContent=r())}o(()=>t.parentElement.replaceChild(i,t))}}(i);break;case Node.ELEMENT_NODE:if(i!==t&&(i.hasAttribute("x-data")&&!l(i)&&i.setAttribute("x-format",""),l(i)))break;!function(e){for(let t of e.childNodes)a(t)}(i),function(t){for(let o of t.attributes)if([...o.value.matchAll(r)].length){const a=o.value;u(()=>o.value=a.replace(r,(o,a)=>e(n,t,a)()))}}(i)}}(t)})}(u),function({addScopeToNode:e,directive:t,initTree:n,mutateDom:o}){t("fragment",(t,{},{cleanup:i})=>{l(t)?g(t,t,{addScopeToNode:e,cleanup:i,initTree:n,mutateDom:o}):a("x-fragment can only be used on a 'template' tag")})}(u),function({addScopeToNode:t,directive:n,initTree:o,mutateDom:i}){n("match",(n,{},{cleanup:r,effect:c,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();c(()=>{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(),g(n,a.el,{addScopeToNode:t,cleanup:r,initTree:o,mutateDom:i}))):d()})})}(u),function(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")})}(u),function({addScopeToNode:t,directive:n,initTree:o,mutateDom:i}){n("when",(n,{expression:r},{cleanup:c,effect:u,evaluateLater:s})=>{if(!l(n))return void a("x-when can only be used on a 'template' tag");const d=e(s,r);u(()=>d()?g(n,n,{addScopeToNode:t,cleanup:c,initTree:o,mutateDom:i}):n._r_block?.delete())})}(u)}document.addEventListener("alpine:init",()=>{Alpine.plugin(T)})}();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ramstack/alpinegear-main",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.4",
|
|
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",
|
|
@@ -11,7 +11,13 @@
|
|
|
11
11
|
},
|
|
12
12
|
"keywords": [
|
|
13
13
|
"alpine.js",
|
|
14
|
-
"alpinejs"
|
|
14
|
+
"alpinejs",
|
|
15
|
+
"alpinejs-binding",
|
|
16
|
+
"alpinejs-fragment",
|
|
17
|
+
"alpinejs-directive",
|
|
18
|
+
"alpinejs-plugin",
|
|
19
|
+
"template",
|
|
20
|
+
"formatting"
|
|
15
21
|
],
|
|
16
22
|
"main": "alpinegear-main.js",
|
|
17
23
|
"module": "alpinegear-main.esm.js"
|