@ramstack/alpinegear-format 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.
package/alpinegear-format.esm.js
CHANGED
|
@@ -15,7 +15,6 @@ const has_modifier = (modifiers, modifier) => modifiers.includes(modifier);
|
|
|
15
15
|
|
|
16
16
|
function plugin({ directive, evaluateLater, mutateDom }) {
|
|
17
17
|
directive("format", (el, { modifiers }, { effect }) => {
|
|
18
|
-
const placeholder_regex = /{{(?<expr>.+?)}}/g;
|
|
19
18
|
const is_once = has_modifier(modifiers, "once");
|
|
20
19
|
const has_format_attr = el => el.hasAttribute("x-format");
|
|
21
20
|
|
|
@@ -67,7 +66,7 @@ function plugin({ directive, evaluateLater, mutateDom }) {
|
|
|
67
66
|
}
|
|
68
67
|
|
|
69
68
|
function process_text_node(node) {
|
|
70
|
-
const tokens = node.textContent.split(
|
|
69
|
+
const tokens = node.textContent.split(/{{(?<expr>.+?)}}/g);
|
|
71
70
|
|
|
72
71
|
if (tokens.length > 1) {
|
|
73
72
|
const fragment = new DocumentFragment();
|
|
@@ -92,10 +91,19 @@ function plugin({ directive, evaluateLater, mutateDom }) {
|
|
|
92
91
|
|
|
93
92
|
function process_attributes(node) {
|
|
94
93
|
for (let attr of node.attributes) {
|
|
95
|
-
const matches = [...attr.value.matchAll(
|
|
94
|
+
const matches = [...attr.value.matchAll(/{{(?<expr>.+?)}}/g)];
|
|
96
95
|
if (matches.length) {
|
|
96
|
+
const getters = new Map(
|
|
97
|
+
matches.map(m => [
|
|
98
|
+
m.groups.expr,
|
|
99
|
+
create_getter(
|
|
100
|
+
evaluateLater,
|
|
101
|
+
node,
|
|
102
|
+
m.groups.expr)]));
|
|
103
|
+
|
|
97
104
|
const template = attr.value;
|
|
98
|
-
|
|
105
|
+
|
|
106
|
+
update(() => attr.value = template.replace(/{{(?<expr>.+?)}}/g, (_, expr) => getters.get(expr)()));
|
|
99
107
|
}
|
|
100
108
|
}
|
|
101
109
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function
|
|
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:r})=>{const c=(e=>e.includes("once"))(a),f=e=>e.hasAttribute("x-format");function i(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]),f=document.createTextNode("");r.append(f),i(()=>f.textContent=c())}o(()=>t.parentElement.replaceChild(r,t))}}(r);break;case Node.ELEMENT_NODE:if(r!==t&&(r.hasAttribute("x-data")&&!f(r)&&r.setAttribute("x-format",""),f(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;i(()=>o.value=c.replace(/{{(?<expr>.+?)}}/g,(e,t)=>r.get(t)()))}}}(r)}}(t)})}export{t as default,t as format};
|
package/alpinegear-format.js
CHANGED
|
@@ -23,7 +23,6 @@
|
|
|
23
23
|
|
|
24
24
|
function plugin({ directive, evaluateLater, mutateDom }) {
|
|
25
25
|
directive("format", (el, { modifiers }, { effect }) => {
|
|
26
|
-
const placeholder_regex = /{{(?<expr>.+?)}}/g;
|
|
27
26
|
const is_once = has_modifier(modifiers, "once");
|
|
28
27
|
const has_format_attr = el => el.hasAttribute("x-format");
|
|
29
28
|
|
|
@@ -75,7 +74,7 @@
|
|
|
75
74
|
}
|
|
76
75
|
|
|
77
76
|
function process_text_node(node) {
|
|
78
|
-
const tokens = node.textContent.split(
|
|
77
|
+
const tokens = node.textContent.split(/{{(?<expr>.+?)}}/g);
|
|
79
78
|
|
|
80
79
|
if (tokens.length > 1) {
|
|
81
80
|
const fragment = new DocumentFragment();
|
|
@@ -100,10 +99,19 @@
|
|
|
100
99
|
|
|
101
100
|
function process_attributes(node) {
|
|
102
101
|
for (let attr of node.attributes) {
|
|
103
|
-
const matches = [...attr.value.matchAll(
|
|
102
|
+
const matches = [...attr.value.matchAll(/{{(?<expr>.+?)}}/g)];
|
|
104
103
|
if (matches.length) {
|
|
104
|
+
const getters = new Map(
|
|
105
|
+
matches.map(m => [
|
|
106
|
+
m.groups.expr,
|
|
107
|
+
create_getter(
|
|
108
|
+
evaluateLater,
|
|
109
|
+
node,
|
|
110
|
+
m.groups.expr)]));
|
|
111
|
+
|
|
105
112
|
const template = attr.value;
|
|
106
|
-
|
|
113
|
+
|
|
114
|
+
update(() => attr.value = template.replace(/{{(?<expr>.+?)}}/g, (_, expr) => getters.get(expr)()));
|
|
107
115
|
}
|
|
108
116
|
}
|
|
109
117
|
}
|
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:
|
|
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:r},{effect:i})=>{const a=(e=>e.includes("once"))(r),c=e=>e.hasAttribute("x-format");function u(e){a?o(()=>e()):i(()=>o(()=>e()))}!function r(i){switch(i.nodeType){case Node.TEXT_NODE:!function(t){const r=t.textContent.split(/{{(?<expr>.+?)}}/g);if(r.length>1){const i=new DocumentFragment;for(let o=0;r.length>o;o++)if(o%2==0)i.appendChild(document.createTextNode(r[o]));else{const a=e(n,t.parentNode,r[o]),c=document.createTextNode("");i.append(c),u(()=>c.textContent=a())}o(()=>t.parentElement.replaceChild(i,t))}}(i);break;case Node.ELEMENT_NODE:if(i!==t&&(i.hasAttribute("x-data")&&!c(i)&&i.setAttribute("x-format",""),c(i)))break;!function(e){for(let t of e.childNodes)r(t)}(i),function(t){for(let o of t.attributes){const r=[...o.value.matchAll(/{{(?<expr>.+?)}}/g)];if(r.length){const i=new Map(r.map(o=>[o.groups.expr,e(n,t,o.groups.expr)])),a=o.value;u(()=>o.value=a.replace(/{{(?<expr>.+?)}}/g,(e,t)=>i.get(t)()))}}}(i)}}(t)})}document.addEventListener("alpine:init",()=>Alpine.plugin(t),void 0)}();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ramstack/alpinegear-format",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.5",
|
|
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",
|