@ramstack/alpinegear-format 1.1.0-preview.3 → 1.1.0-preview.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
|
@@ -11,31 +11,18 @@ function has_getter(value) {
|
|
|
11
11
|
return typeof value?.get === "function";
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
const is_nullish = value => value === null || value === undefined;
|
|
15
14
|
const has_modifier = (modifiers, modifier) => modifiers.includes(modifier);
|
|
16
15
|
|
|
17
|
-
function plugin({ directive, mutateDom }) {
|
|
18
|
-
directive("format", (el, { modifiers }, { effect
|
|
19
|
-
const cache = new Map;
|
|
16
|
+
function plugin({ directive, evaluateLater, mutateDom }) {
|
|
17
|
+
directive("format", (el, { modifiers }, { effect }) => {
|
|
20
18
|
const placeholder_regex = /{{(?<expr>.+?)}}/g;
|
|
21
19
|
const is_once = has_modifier(modifiers, "once");
|
|
22
20
|
|
|
23
21
|
process(el);
|
|
24
22
|
|
|
25
|
-
function get_eval_fn(expression) {
|
|
26
|
-
let getter = cache.get(expression);
|
|
27
|
-
if (is_nullish(getter)) {
|
|
28
|
-
getter = create_getter(evaluateLater, expression);
|
|
29
|
-
cache.set(expression, getter);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
return getter;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
23
|
function update(callback) {
|
|
36
24
|
if (is_once) {
|
|
37
25
|
mutateDom(() => callback());
|
|
38
|
-
cache.clear();
|
|
39
26
|
}
|
|
40
27
|
else {
|
|
41
28
|
effect(() => mutateDom(() => callback()));
|
|
@@ -66,7 +53,7 @@ function plugin({ directive, mutateDom }) {
|
|
|
66
53
|
fragment.appendChild(document.createTextNode(tokens[i]));
|
|
67
54
|
}
|
|
68
55
|
else {
|
|
69
|
-
const get_value =
|
|
56
|
+
const get_value = create_getter(evaluateLater, node.parentNode, tokens[i]);
|
|
70
57
|
const text = document.createTextNode("");
|
|
71
58
|
|
|
72
59
|
fragment.append(text);
|
|
@@ -84,7 +71,7 @@ function plugin({ directive, mutateDom }) {
|
|
|
84
71
|
const matches = [...attr.value.matchAll(placeholder_regex)];
|
|
85
72
|
if (matches.length) {
|
|
86
73
|
const template = attr.value;
|
|
87
|
-
update(() => attr.value = template.replace(placeholder_regex, (_, expr) =>
|
|
74
|
+
update(() => attr.value = template.replace(placeholder_regex, (_, expr) => create_getter(evaluateLater, node, expr)()));
|
|
88
75
|
}
|
|
89
76
|
}
|
|
90
77
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function e(
|
|
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:c},{effect:a})=>{const r=/{{(?<expr>.+?)}}/g,f=(e=>e.includes("once"))(c);function i(e){f?o((()=>e())):a((()=>o((()=>e()))))}!function t(c){switch(c.nodeType){case Node.TEXT_NODE:!function(t){const c=t.textContent.split(r);if(c.length>1){const a=new DocumentFragment;for(let o=0;c.length>o;o++)if(o%2==0)a.appendChild(document.createTextNode(c[o]));else{const r=e(n,t.parentNode,c[o]),f=document.createTextNode("");a.append(f),i((()=>f.textContent=r()))}o((()=>t.parentElement.replaceChild(a,t)))}}(c);break;case Node.ELEMENT_NODE:!function(e){for(let n of e.childNodes)t(n)}(c),function(t){for(let o of t.attributes)if([...o.value.matchAll(r)].length){const c=o.value;i((()=>o.value=c.replace(r,((o,c)=>e(n,t,c)()))))}}(c)}}(t)}))}export{t as format};
|
package/alpinegear-format.js
CHANGED
|
@@ -14,31 +14,18 @@
|
|
|
14
14
|
return typeof value?.get === "function";
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
const is_nullish = value => value === null || value === undefined;
|
|
18
17
|
const has_modifier = (modifiers, modifier) => modifiers.includes(modifier);
|
|
19
18
|
|
|
20
|
-
function plugin({ directive, mutateDom }) {
|
|
21
|
-
directive("format", (el, { modifiers }, { effect
|
|
22
|
-
const cache = new Map;
|
|
19
|
+
function plugin({ directive, evaluateLater, mutateDom }) {
|
|
20
|
+
directive("format", (el, { modifiers }, { effect }) => {
|
|
23
21
|
const placeholder_regex = /{{(?<expr>.+?)}}/g;
|
|
24
22
|
const is_once = has_modifier(modifiers, "once");
|
|
25
23
|
|
|
26
24
|
process(el);
|
|
27
25
|
|
|
28
|
-
function get_eval_fn(expression) {
|
|
29
|
-
let getter = cache.get(expression);
|
|
30
|
-
if (is_nullish(getter)) {
|
|
31
|
-
getter = create_getter(evaluateLater, expression);
|
|
32
|
-
cache.set(expression, getter);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return getter;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
26
|
function update(callback) {
|
|
39
27
|
if (is_once) {
|
|
40
28
|
mutateDom(() => callback());
|
|
41
|
-
cache.clear();
|
|
42
29
|
}
|
|
43
30
|
else {
|
|
44
31
|
effect(() => mutateDom(() => callback()));
|
|
@@ -69,7 +56,7 @@
|
|
|
69
56
|
fragment.appendChild(document.createTextNode(tokens[i]));
|
|
70
57
|
}
|
|
71
58
|
else {
|
|
72
|
-
const get_value =
|
|
59
|
+
const get_value = create_getter(evaluateLater, node.parentNode, tokens[i]);
|
|
73
60
|
const text = document.createTextNode("");
|
|
74
61
|
|
|
75
62
|
fragment.append(text);
|
|
@@ -87,7 +74,7 @@
|
|
|
87
74
|
const matches = [...attr.value.matchAll(placeholder_regex)];
|
|
88
75
|
if (matches.length) {
|
|
89
76
|
const template = attr.value;
|
|
90
|
-
update(() => attr.value = template.replace(placeholder_regex, (_, expr) =>
|
|
77
|
+
update(() => attr.value = template.replace(placeholder_regex, (_, expr) => create_getter(evaluateLater, node, expr)()));
|
|
91
78
|
}
|
|
92
79
|
}
|
|
93
80
|
}
|
package/alpinegear-format.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(){"use strict";function e(
|
|
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,l=(e=>e.includes("once"))(c);function r(e){l?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]),l=document.createTextNode("");i.append(l),r((()=>l.textContent=a()))}o((()=>t.parentElement.replaceChild(i,t)))}}(c);break;case Node.ELEMENT_NODE:!function(e){for(let n of e.childNodes)t(n)}(c),function(t){for(let o of t.attributes)if([...o.value.matchAll(a)].length){const c=o.value;r((()=>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.1.0-preview.
|
|
3
|
+
"version": "1.1.0-preview.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",
|