@ramstack/alpinegear-format 1.2.1 → 1.2.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.
@@ -37,6 +37,30 @@ function plugin({ directive, evaluateLater, mutateDom }) {
37
37
  break;
38
38
 
39
39
  case Node.ELEMENT_NODE:
40
+ if (node !== el) {
41
+
42
+
43
+
44
+
45
+
46
+
47
+
48
+
49
+
50
+
51
+
52
+
53
+
54
+ if (node.hasAttribute("x-data") && !has_format_attr(node)) {
55
+ node.setAttribute("x-format", "");
56
+ }
57
+
58
+ if (has_format_attr(node)) {
59
+ break;
60
+ }
61
+ }
62
+
63
+
40
64
  process_nodes(node);
41
65
  process_attributes(node);
42
66
  break;
@@ -79,29 +103,6 @@ function plugin({ directive, evaluateLater, mutateDom }) {
79
103
 
80
104
  function process_nodes(node) {
81
105
  for (let child of node.childNodes) {
82
- if (child.nodeType === Node.ELEMENT_NODE) {
83
- //
84
- // When we encounter an element with the 'x-data' attribute, its properties
85
- // are not yet initialized, and the Alpine context is unavailable.
86
- // Attempting to use these properties will result in
87
- // an "Alpine Expression Error: [expression] is not defined".
88
-
89
-
90
-
91
-
92
-
93
-
94
-
95
-
96
- if (child.hasAttribute("x-data") && !has_format_attr(child)) {
97
- child.setAttribute("x-format", "");
98
- }
99
-
100
- if (has_format_attr(child)) {
101
- continue;
102
- }
103
- }
104
-
105
106
  process(child);
106
107
  }
107
108
  }
@@ -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({directive:t,evaluateLater:n,mutateDom:o}){t("format",(t,{modifiers:a},{effect:c})=>{const r=/{{(?<expr>.+?)}}/g,i=(e=>e.includes("once"))(a),f=e=>e.hasAttribute("x-format");function u(e){i?o(()=>e()):c(()=>o(()=>e()))}!function t(a){switch(a.nodeType){case Node.TEXT_NODE:!function(t){const a=t.textContent.split(r);if(a.length>1){const c=new DocumentFragment;for(let o=0;a.length>o;o++)if(o%2==0)c.appendChild(document.createTextNode(a[o]));else{const r=e(n,t.parentNode,a[o]),i=document.createTextNode("");c.append(i),u(()=>i.textContent=r())}o(()=>t.parentElement.replaceChild(c,t))}}(a);break;case Node.ELEMENT_NODE:!function(e){for(let n of e.childNodes)n.nodeType===Node.ELEMENT_NODE&&(n.hasAttribute("x-data")&&!f(n)&&n.setAttribute("x-format",""),f(n))||t(n)}(a),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)()))}}(a)}}(t)})}export{t as format};
1
+ function t(t,...e){const n=t(...e);return()=>{let t;return n(e=>t=e),e=t,"function"==typeof e?.get?t.get():t;var e}}function e({directive:e,evaluateLater:n,mutateDom:o}){e("format",(e,{modifiers:a},{effect:c})=>{const r=/{{(?<expr>.+?)}}/g,i=(t=>t.includes("once"))(a),f=t=>t.hasAttribute("x-format");function u(t){i?o(()=>t()):c(()=>o(()=>t()))}!function a(c){switch(c.nodeType){case Node.TEXT_NODE:!function(e){const a=e.textContent.split(r);if(a.length>1){const c=new DocumentFragment;for(let o=0;a.length>o;o++)if(o%2==0)c.appendChild(document.createTextNode(a[o]));else{const r=t(n,e.parentNode,a[o]),i=document.createTextNode("");c.append(i),u(()=>i.textContent=r())}o(()=>e.parentElement.replaceChild(c,e))}}(c);break;case Node.ELEMENT_NODE:if(c!==e&&(c.hasAttribute("x-data")&&!f(c)&&c.setAttribute("x-format",""),f(c)))break;!function(t){for(let e of t.childNodes)a(e)}(c),function(e){for(let o of e.attributes)if([...o.value.matchAll(r)].length){const a=o.value;u(()=>o.value=a.replace(r,(o,a)=>t(n,e,a)()))}}(c)}}(e)})}export{e as format};
@@ -40,6 +40,30 @@
40
40
  break;
41
41
 
42
42
  case Node.ELEMENT_NODE:
43
+ if (node !== el) {
44
+
45
+
46
+
47
+
48
+
49
+
50
+
51
+
52
+
53
+
54
+
55
+
56
+
57
+ if (node.hasAttribute("x-data") && !has_format_attr(node)) {
58
+ node.setAttribute("x-format", "");
59
+ }
60
+
61
+ if (has_format_attr(node)) {
62
+ break;
63
+ }
64
+ }
65
+
66
+
43
67
  process_nodes(node);
44
68
  process_attributes(node);
45
69
  break;
@@ -82,29 +106,6 @@
82
106
 
83
107
  function process_nodes(node) {
84
108
  for (let child of node.childNodes) {
85
- if (child.nodeType === Node.ELEMENT_NODE) {
86
- //
87
- // When we encounter an element with the 'x-data' attribute, its properties
88
- // are not yet initialized, and the Alpine context is unavailable.
89
- // Attempting to use these properties will result in
90
- // an "Alpine Expression Error: [expression] is not defined".
91
-
92
-
93
-
94
-
95
-
96
-
97
-
98
-
99
- if (child.hasAttribute("x-data") && !has_format_attr(child)) {
100
- child.setAttribute("x-format", "");
101
- }
102
-
103
- if (has_format_attr(child)) {
104
- continue;
105
- }
106
- }
107
-
108
109
  process(child);
109
110
  }
110
111
  }
@@ -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({directive:t,evaluateLater:n,mutateDom:o}){t("format",(t,{modifiers:c},{effect:i})=>{const a=/{{(?<expr>.+?)}}/g,r=(e=>e.includes("once"))(c),u=e=>e.hasAttribute("x-format");function l(e){r?o(()=>e()):i(()=>o(()=>e()))}!function t(c){switch(c.nodeType){case Node.TEXT_NODE:!function(t){const c=t.textContent.split(a);if(c.length>1){const i=new DocumentFragment;for(let o=0;c.length>o;o++)if(o%2==0)i.appendChild(document.createTextNode(c[o]));else{const a=e(n,t.parentNode,c[o]),r=document.createTextNode("");i.append(r),l(()=>r.textContent=a())}o(()=>t.parentElement.replaceChild(i,t))}}(c);break;case Node.ELEMENT_NODE:!function(e){for(let n of e.childNodes)n.nodeType===Node.ELEMENT_NODE&&(n.hasAttribute("x-data")&&!u(n)&&n.setAttribute("x-format",""),u(n))||t(n)}(c),function(t){for(let o of t.attributes)if([...o.value.matchAll(a)].length){const c=o.value;l(()=>o.value=c.replace(a,(o,c)=>e(n,t,c)()))}}(c)}}(t)})}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({directive:t,evaluateLater:n,mutateDom:o}){t("format",(t,{modifiers:i},{effect:c})=>{const a=/{{(?<expr>.+?)}}/g,r=(e=>e.includes("once"))(i),u=e=>e.hasAttribute("x-format");function f(e){r?o(()=>e()):c(()=>o(()=>e()))}!function i(c){switch(c.nodeType){case Node.TEXT_NODE:!function(t){const i=t.textContent.split(a);if(i.length>1){const c=new DocumentFragment;for(let o=0;i.length>o;o++)if(o%2==0)c.appendChild(document.createTextNode(i[o]));else{const a=e(n,t.parentNode,i[o]),r=document.createTextNode("");c.append(r),f(()=>r.textContent=a())}o(()=>t.parentElement.replaceChild(c,t))}}(c);break;case Node.ELEMENT_NODE:if(c!==t&&(c.hasAttribute("x-data")&&!u(c)&&c.setAttribute("x-format",""),u(c)))break;!function(e){for(let t of e.childNodes)i(t)}(c),function(t){for(let o of t.attributes)if([...o.value.matchAll(a)].length){const i=o.value;f(()=>o.value=i.replace(a,(o,i)=>e(n,t,i)()))}}(c)}}(t)})}document.addEventListener("alpine:init",()=>{Alpine.plugin(t)})}();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ramstack/alpinegear-format",
3
- "version": "1.2.1",
3
+ "version": "1.2.2",
4
4
  "description": "@ramstack/alpinegear-format provides 'x-format' Alpine.js directive, which allows you to easily interpolate text using a template syntax similar to what's available in Vue.js.",
5
5
  "author": "Rameel Burhan",
6
6
  "license": "MIT",