@ramstack/alpinegear-format 1.2.0 → 1.2.1
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/alpinegear-format.esm.js
CHANGED
|
@@ -17,6 +17,7 @@ function plugin({ directive, evaluateLater, mutateDom }) {
|
|
|
17
17
|
directive("format", (el, { modifiers }, { effect }) => {
|
|
18
18
|
const placeholder_regex = /{{(?<expr>.+?)}}/g;
|
|
19
19
|
const is_once = has_modifier(modifiers, "once");
|
|
20
|
+
const has_format_attr = el => el.hasAttribute("x-format");
|
|
20
21
|
|
|
21
22
|
process(el);
|
|
22
23
|
|
|
@@ -78,6 +79,29 @@ function plugin({ directive, evaluateLater, mutateDom }) {
|
|
|
78
79
|
|
|
79
80
|
function process_nodes(node) {
|
|
80
81
|
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
|
+
|
|
81
105
|
process(child);
|
|
82
106
|
}
|
|
83
107
|
}
|
|
@@ -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:
|
|
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};
|
package/alpinegear-format.js
CHANGED
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
directive("format", (el, { modifiers }, { effect }) => {
|
|
21
21
|
const placeholder_regex = /{{(?<expr>.+?)}}/g;
|
|
22
22
|
const is_once = has_modifier(modifiers, "once");
|
|
23
|
+
const has_format_attr = el => el.hasAttribute("x-format");
|
|
23
24
|
|
|
24
25
|
process(el);
|
|
25
26
|
|
|
@@ -81,6 +82,29 @@
|
|
|
81
82
|
|
|
82
83
|
function process_nodes(node) {
|
|
83
84
|
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
|
+
|
|
84
108
|
process(child);
|
|
85
109
|
}
|
|
86
110
|
}
|
package/alpinegear-format.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({directive:t,evaluateLater:n,mutateDom:o}){t("format",(t,{modifiers:c},{effect:i})=>{const a=/{{(?<expr>.+?)}}/g,
|
|
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)})}();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ramstack/alpinegear-format",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.1",
|
|
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",
|