@useinsider/guido 3.18.0-beta.d542b1f → 3.18.0-beta.dc6c376
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.
|
@@ -1,93 +1,86 @@
|
|
|
1
|
-
import { getCsrfToken as
|
|
2
|
-
import { ref as p, computed as
|
|
3
|
-
const
|
|
4
|
-
const
|
|
1
|
+
import { getCsrfToken as H } from "../utils/genericUtil.js";
|
|
2
|
+
import { ref as p, computed as T } from "vue";
|
|
3
|
+
const k = (b = {}) => {
|
|
4
|
+
const h = p(!1), a = p(null), u = p(null), g = T(() => h.value), y = T(() => a.value !== null), v = {
|
|
5
5
|
baseURL: "",
|
|
6
6
|
timeout: 1e4,
|
|
7
7
|
retry: 0,
|
|
8
8
|
retryDelay: 1e3,
|
|
9
9
|
headers: {
|
|
10
10
|
"Content-Type": "application/json",
|
|
11
|
-
"X-CSRF-TOKEN":
|
|
11
|
+
"X-CSRF-TOKEN": H()
|
|
12
12
|
},
|
|
13
13
|
...b
|
|
14
|
-
},
|
|
14
|
+
}, w = (e, s) => {
|
|
15
15
|
if (e.startsWith("http://") || e.startsWith("https://"))
|
|
16
16
|
return e;
|
|
17
|
-
const t =
|
|
17
|
+
const t = s || v.baseURL || "";
|
|
18
18
|
return t.endsWith("/") && e.startsWith("/") ? `${t}${e.slice(1)}` : t.endsWith("/") || e.startsWith("/") ? `${t}${e}` : `${t}/${e}`;
|
|
19
|
-
},
|
|
19
|
+
}, P = (e) => new Promise((s, t) => {
|
|
20
20
|
setTimeout(() => {
|
|
21
21
|
t(new Error("Request timeout"));
|
|
22
22
|
}, e);
|
|
23
|
-
}),
|
|
24
|
-
setTimeout(
|
|
25
|
-
}), i = async (e,
|
|
26
|
-
|
|
27
|
-
const
|
|
23
|
+
}), x = (e) => new Promise((s) => {
|
|
24
|
+
setTimeout(s, e);
|
|
25
|
+
}), i = async (e, s, t, D = {}) => {
|
|
26
|
+
a.value = null, h.value = !0, u.value = new AbortController();
|
|
27
|
+
const n = { ...v, ...D }, L = w(s, n.baseURL), c = {
|
|
28
28
|
method: e,
|
|
29
|
-
headers: { ...
|
|
29
|
+
headers: { ...n.headers },
|
|
30
30
|
signal: u.value.signal,
|
|
31
|
-
...
|
|
31
|
+
...n
|
|
32
32
|
};
|
|
33
33
|
t && ["POST", "PUT", "PATCH"].includes(e) && (t instanceof FormData ? (delete c.headers["Content-Type"], c.body = t) : c.body = JSON.stringify(t));
|
|
34
34
|
const E = async (m = 0) => {
|
|
35
35
|
try {
|
|
36
|
-
const o = [fetch(
|
|
37
|
-
|
|
38
|
-
const
|
|
39
|
-
if (!
|
|
40
|
-
const O = `HTTP Error: ${
|
|
41
|
-
throw
|
|
42
|
-
detail: {
|
|
43
|
-
status: s.status,
|
|
44
|
-
body: H,
|
|
45
|
-
url: new URL(T, window.location.href).href
|
|
46
|
-
}
|
|
47
|
-
}))).catch(() => {
|
|
48
|
-
}), h;
|
|
36
|
+
const o = [fetch(L, c)];
|
|
37
|
+
n.timeout && o.push(P(n.timeout));
|
|
38
|
+
const r = await Promise.race(o);
|
|
39
|
+
if (!r.ok) {
|
|
40
|
+
const O = `HTTP Error: ${r.status} ${r.statusText}`, d = new Error(O);
|
|
41
|
+
throw d.status = r.status, d.statusText = r.statusText, d.response = r, d;
|
|
49
42
|
}
|
|
50
43
|
let f;
|
|
51
|
-
const l =
|
|
52
|
-
return l != null && l.includes("application/json") ? f = await
|
|
44
|
+
const l = r.headers.get("content-type");
|
|
45
|
+
return l != null && l.includes("application/json") ? f = await r.json() : l != null && l.includes("text/") ? f = await r.text() : f = await r.blob(), {
|
|
53
46
|
data: f,
|
|
54
|
-
status:
|
|
55
|
-
statusText:
|
|
56
|
-
headers:
|
|
47
|
+
status: r.status,
|
|
48
|
+
statusText: r.statusText,
|
|
49
|
+
headers: r.headers
|
|
57
50
|
};
|
|
58
51
|
} catch (o) {
|
|
59
|
-
const
|
|
60
|
-
if (m < (
|
|
61
|
-
return await
|
|
62
|
-
throw o instanceof Error ? o.name === "AbortError" ?
|
|
52
|
+
const r = o instanceof Error && o.name === "AbortError";
|
|
53
|
+
if (m < (n.retry || 0) && !r)
|
|
54
|
+
return await x(n.retryDelay || 1e3), E(m + 1);
|
|
55
|
+
throw o instanceof Error ? o.name === "AbortError" ? a.value = { message: "Request was cancelled" } : a.value = { message: o.message } : a.value = o, o;
|
|
63
56
|
}
|
|
64
57
|
};
|
|
65
58
|
try {
|
|
66
59
|
return await E();
|
|
67
60
|
} finally {
|
|
68
|
-
|
|
61
|
+
h.value = !1, u.value = null;
|
|
69
62
|
}
|
|
70
|
-
},
|
|
63
|
+
}, C = (e, s) => i("GET", e, void 0, s), $ = (e, s, t) => i("POST", e, s, t), R = (e, s, t) => i("PUT", e, s, t), U = (e, s, t) => i("PATCH", e, s, t), A = (e, s) => i("DELETE", e, void 0, s), W = (e) => {
|
|
71
64
|
u.value && u.value.abort(e);
|
|
72
65
|
}, q = () => {
|
|
73
|
-
|
|
66
|
+
a.value = null;
|
|
74
67
|
};
|
|
75
68
|
return {
|
|
76
69
|
// State
|
|
77
70
|
loading: g,
|
|
78
|
-
error:
|
|
71
|
+
error: T(() => a.value),
|
|
79
72
|
hasError: y,
|
|
80
73
|
// Methods
|
|
81
74
|
request: i,
|
|
82
|
-
get:
|
|
83
|
-
post:
|
|
84
|
-
put:
|
|
85
|
-
patch:
|
|
86
|
-
delete:
|
|
75
|
+
get: C,
|
|
76
|
+
post: $,
|
|
77
|
+
put: R,
|
|
78
|
+
patch: U,
|
|
79
|
+
delete: A,
|
|
87
80
|
cancel: W,
|
|
88
81
|
clearError: q
|
|
89
82
|
};
|
|
90
83
|
};
|
|
91
84
|
export {
|
|
92
|
-
|
|
85
|
+
k as useHttp
|
|
93
86
|
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { BaseDynamicContent } from '@@/Types/generic';
|
|
2
|
+
export type DynamicContentFormat = NonNullable<BaseDynamicContent['format']>;
|
|
3
|
+
/** Format key the dynamic-content picker sends for a custom date/time format. */
|
|
4
|
+
export declare const TIME_FORMAT_KEY = "time-format";
|
|
5
|
+
/** Wraps a Liquid filter argument in whichever quote style the value itself does not use. */
|
|
6
|
+
export declare const quoteArgument: (value: string) => string | null;
|
|
7
|
+
/**
|
|
8
|
+
* `{ key: 'time-format', value: '%Y-%m-%d' }` -> `date: "%Y-%m-%d"`.
|
|
9
|
+
*
|
|
10
|
+
* Only a custom date/time strftime pattern has a Liquid equivalent. Anything else returns null so
|
|
11
|
+
* the caller emits a plain tag rather than one that silently lost — or literally printed — its
|
|
12
|
+
* format.
|
|
13
|
+
* @example formatToLiquidFilter({ key: 'time-format', value: '%b %-d, %Y' }) -> date: "%b %-d, %Y"
|
|
14
|
+
*/
|
|
15
|
+
export declare const formatToLiquidFilter: (format: DynamicContentFormat) => string | null;
|
|
16
|
+
/**
|
|
17
|
+
* Inverse of `formatToLiquidFilter` — reads the picker format back out of one filter segment, so a
|
|
18
|
+
* reopened tag restores its selection in the host's format dropdown.
|
|
19
|
+
*/
|
|
20
|
+
export declare const liquidFilterToFormat: (segment: string) => DynamicContentFormat | null;
|
|
@@ -1,69 +1,72 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { formatToLiquidFilter as b, quoteArgument as v, liquidFilterToFormat as h } from "./liquidDynamicContent.js";
|
|
2
|
+
const g = (t) => {
|
|
3
|
+
if (!t.includes("="))
|
|
4
|
+
return null;
|
|
5
|
+
const [e, a] = t.split("=");
|
|
6
|
+
return { key: e.trim(), value: a.trim() };
|
|
7
|
+
}, c = "default:", f = (t) => {
|
|
8
|
+
if (!t.startsWith(c))
|
|
9
|
+
return t;
|
|
10
|
+
const e = t.slice(c.length).trim(), a = (l) => e.length >= 2 && e.startsWith(l) && e.endsWith(l);
|
|
11
|
+
return a('"') || a("'") ? e.slice(1, -1) : e;
|
|
12
|
+
}, $ = (t) => {
|
|
13
|
+
const a = t.value.match(/\{\{([^}]+)\}\}/)[1].split("|").map((r) => r.trim()), [l] = a, s = {
|
|
3
14
|
text: t.label,
|
|
4
|
-
value:
|
|
15
|
+
value: l || ""
|
|
5
16
|
};
|
|
6
17
|
if (a.length >= 2) {
|
|
7
|
-
const [,
|
|
8
|
-
if (
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
n ? r.format = n : e || (r.fallback = l), e && (r.fallback = e);
|
|
18
|
+
const [, r, n] = a;
|
|
19
|
+
if (r.startsWith(c))
|
|
20
|
+
s.fallback = f(r);
|
|
21
|
+
else {
|
|
22
|
+
const o = h(r) ?? g(r);
|
|
23
|
+
o ? s.format = o : n || (s.fallback = r), n && (s.fallback = f(n));
|
|
14
24
|
}
|
|
15
25
|
}
|
|
16
|
-
return
|
|
17
|
-
},
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
};
|
|
23
|
-
if (c) {
|
|
24
|
-
if (!a.fallback)
|
|
25
|
-
return {
|
|
26
|
-
label: a.text,
|
|
27
|
-
value: `{{ ${a.value} }}`
|
|
28
|
-
};
|
|
29
|
-
const r = !Number.isNaN(Number(a.fallback)) && a.fallback.trim() !== "" ? a.fallback : `"${a.fallback}"`;
|
|
30
|
-
return {
|
|
31
|
-
label: `${a.text} | ${a.fallback}`,
|
|
32
|
-
value: `{{ ${a.value} | default: ${r} }}`
|
|
33
|
-
};
|
|
34
|
-
}
|
|
26
|
+
return s;
|
|
27
|
+
}, m = (t) => {
|
|
28
|
+
const a = !Number.isNaN(Number(t)) && t.trim() !== "" ? t : v(t);
|
|
29
|
+
return a === null ? null : `${c} ${a}`;
|
|
30
|
+
}, k = (t) => {
|
|
31
|
+
const e = t.format ? b(t.format) : null, a = t.fallback ? m(t.fallback) : null, l = [t.value, e, a].filter(Boolean);
|
|
35
32
|
return {
|
|
36
|
-
label:
|
|
37
|
-
value:
|
|
33
|
+
label: [t.text, e, a && t.fallback].filter(Boolean).join(" | "),
|
|
34
|
+
value: `{{ ${l.join(" | ")} }}`
|
|
38
35
|
};
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
36
|
+
}, i = (t, e = !1) => t.map((a) => e ? k(a) : a.format ? {
|
|
37
|
+
label: `${a.text} | ${a.format.key}=${a.format.value}`,
|
|
38
|
+
value: `{{${a.value}|${a.format.key}=${a.format.value}}}`
|
|
39
|
+
} : {
|
|
40
|
+
label: a.fallback ? `${a.text} | ${a.fallback}` : a.text,
|
|
41
|
+
value: a.fallback ? `{{${a.value}|${a.fallback}}}` : `{{${a.value}}}`
|
|
42
|
+
}), d = (t) => {
|
|
43
|
+
const e = [], a = /* @__PURE__ */ new Set(), l = (r) => {
|
|
44
|
+
Array.isArray(r) && r.forEach((n) => {
|
|
45
|
+
const o = [...n.children ?? [], ...n.select_items ?? []];
|
|
46
|
+
if (o.length > 0) {
|
|
47
|
+
l(o);
|
|
45
48
|
return;
|
|
46
49
|
}
|
|
47
|
-
const u =
|
|
48
|
-
u &&
|
|
50
|
+
const u = n.text || n.tag_text;
|
|
51
|
+
u && n.value && !a.has(n.value) && (a.add(n.value), e.push({ text: u, value: n.value }));
|
|
49
52
|
});
|
|
50
|
-
}, [
|
|
51
|
-
return s
|
|
52
|
-
},
|
|
53
|
-
const
|
|
53
|
+
}, [s] = Object.values(t ?? {});
|
|
54
|
+
return l(s), e;
|
|
55
|
+
}, p = (t, e, a = !1) => {
|
|
56
|
+
const l = new Set(t.map((r) => r.value)), s = e.filter((r) => l.has(r.value) ? !1 : (l.add(r.value), !0));
|
|
54
57
|
return [
|
|
55
|
-
...
|
|
56
|
-
...
|
|
58
|
+
...i(t, a),
|
|
59
|
+
...i(s, a)
|
|
57
60
|
];
|
|
58
|
-
},
|
|
61
|
+
}, F = () => {
|
|
59
62
|
var t;
|
|
60
63
|
return ((t = document.head.querySelector('meta[name="csrf-token"]')) == null ? void 0 : t.getAttribute("content")) ?? "";
|
|
61
|
-
},
|
|
64
|
+
}, T = (t) => typeof t == "string" ? t : typeof t == "number" ? String(t) : "";
|
|
62
65
|
export {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
66
|
+
T as asText,
|
|
67
|
+
p as buildMergeTagEntries,
|
|
68
|
+
i as dynamicContentToMergeTags,
|
|
69
|
+
d as flattenDynamicContentList,
|
|
70
|
+
F as getCsrfToken,
|
|
71
|
+
$ as mergeTagToDynamicContent
|
|
69
72
|
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const E = "time-format", r = "date", u = new RegExp(`^${r}\\s*:\\s*(?:"([^"]*)"|'([^']*)')$`), s = /%[-_0^#]?\d*[a-zA-Z%]/, c = new RegExp(s, "g"), l = /\b(?:Y{2,4}|M{2,4}|D{1,4}|d{3,4}|H{2}|h{2}|m{2}|s{2}|S{1,3}|A|a)\b/, T = (t) => t.includes('"') ? t.includes("'") ? null : `'${t}'` : `"${t}"`, i = (t) => s.test(t) && !l.test(t.replace(c, "")), R = (t) => {
|
|
2
|
+
if (t.key !== E || !i(t.value ?? ""))
|
|
3
|
+
return null;
|
|
4
|
+
const n = T(t.value);
|
|
5
|
+
return n === null ? null : `${r}: ${n}`;
|
|
6
|
+
}, _ = (t) => {
|
|
7
|
+
const [, n, o] = t.match(u) ?? [], e = n ?? o;
|
|
8
|
+
return e ? { key: E, value: e } : null;
|
|
9
|
+
};
|
|
10
|
+
export {
|
|
11
|
+
E as TIME_FORMAT_KEY,
|
|
12
|
+
R as formatToLiquidFilter,
|
|
13
|
+
_ as liquidFilterToFormat,
|
|
14
|
+
T as quoteArgument
|
|
15
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@useinsider/guido",
|
|
3
|
-
"version": "3.18.0-beta.
|
|
3
|
+
"version": "3.18.0-beta.dc6c376",
|
|
4
4
|
"description": "Guido is a Vue + TypeScript wrapper for Email Plugin. Easily embed the email editor in your Vue applications.",
|
|
5
5
|
"main": "./dist/guido.umd.cjs",
|
|
6
6
|
"module": "./dist/library.js",
|