@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 S } from "../utils/genericUtil.js";
2
- import { ref as p, computed as v } from "vue";
3
- const F = (b = {}) => {
4
- const d = p(!1), n = p(null), u = p(null), g = v(() => d.value), y = v(() => n.value !== null), w = {
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": S()
11
+ "X-CSRF-TOKEN": H()
12
12
  },
13
13
  ...b
14
- }, P = (e, r) => {
14
+ }, w = (e, s) => {
15
15
  if (e.startsWith("http://") || e.startsWith("https://"))
16
16
  return e;
17
- const t = r || w.baseURL || "";
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
- }, x = (e) => new Promise((r, t) => {
19
+ }, P = (e) => new Promise((s, t) => {
20
20
  setTimeout(() => {
21
21
  t(new Error("Request timeout"));
22
22
  }, e);
23
- }), C = (e) => new Promise((r) => {
24
- setTimeout(r, e);
25
- }), i = async (e, r, t, D = {}) => {
26
- n.value = null, d.value = !0, u.value = new AbortController();
27
- const a = { ...w, ...D }, T = P(r, a.baseURL), c = {
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: { ...a.headers },
29
+ headers: { ...n.headers },
30
30
  signal: u.value.signal,
31
- ...a
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(T, c)];
37
- a.timeout && o.push(x(a.timeout));
38
- const s = await Promise.race(o);
39
- if (!s.ok) {
40
- const O = `HTTP Error: ${s.status} ${s.statusText}`, h = new Error(O);
41
- throw h.status = s.status, h.statusText = s.statusText, h.response = s, [401, 403, 419].includes(s.status) && Promise.resolve().then(() => s.clone().text().catch(() => "")).then((H) => window.dispatchEvent(new CustomEvent("insider:http-auth-error", {
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 = s.headers.get("content-type");
52
- return l != null && l.includes("application/json") ? f = await s.json() : l != null && l.includes("text/") ? f = await s.text() : f = await s.blob(), {
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: s.status,
55
- statusText: s.statusText,
56
- headers: s.headers
47
+ status: r.status,
48
+ statusText: r.statusText,
49
+ headers: r.headers
57
50
  };
58
51
  } catch (o) {
59
- const s = o instanceof Error && o.name === "AbortError";
60
- if (m < (a.retry || 0) && !s)
61
- return await C(a.retryDelay || 1e3), E(m + 1);
62
- throw o instanceof Error ? o.name === "AbortError" ? n.value = { message: "Request was cancelled" } : n.value = { message: o.message } : n.value = o, o;
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
- d.value = !1, u.value = null;
61
+ h.value = !1, u.value = null;
69
62
  }
70
- }, R = (e, r) => i("GET", e, void 0, r), U = (e, r, t) => i("POST", e, r, t), $ = (e, r, t) => i("PUT", e, r, t), A = (e, r, t) => i("PATCH", e, r, t), L = (e, r) => i("DELETE", e, void 0, r), W = (e) => {
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
- n.value = null;
66
+ a.value = null;
74
67
  };
75
68
  return {
76
69
  // State
77
70
  loading: g,
78
- error: v(() => n.value),
71
+ error: T(() => a.value),
79
72
  hasError: y,
80
73
  // Methods
81
74
  request: i,
82
- get: R,
83
- post: U,
84
- put: $,
85
- patch: A,
86
- delete: L,
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
- F as useHttp
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
- const o = (t) => {
2
- const a = t.value.match(/\{\{([^}]+)\}\}/)[1].split("|").map((l) => l.trim()), [s] = a, r = {
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: s || ""
15
+ value: l || ""
5
16
  };
6
17
  if (a.length >= 2) {
7
- const [, l, e] = a;
8
- if (l.startsWith("default:")) {
9
- let n = l.slice(8).trim();
10
- n.startsWith('"') && n.endsWith('"') && (n = n.slice(1, -1)), r.fallback = n;
11
- } else {
12
- const n = l.includes("=") ? { key: l.split("=")[0].trim(), value: l.split("=")[1].trim() } : null;
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 r;
17
- }, f = (t, c = !1) => t.map((a) => {
18
- if (a.format)
19
- return {
20
- label: `${a.text} | ${a.format.key}=${a.format.value}`,
21
- value: `{{${a.value}|${a.format.key}=${a.format.value}}}`
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: a.fallback ? `${a.text} | ${a.fallback}` : a.text,
37
- value: a.fallback ? `{{${a.value}|${a.fallback}}}` : `{{${a.value}}}`
33
+ label: [t.text, e, a && t.fallback].filter(Boolean).join(" | "),
34
+ value: `{{ ${l.join(" | ")} }}`
38
35
  };
39
- }), b = (t) => {
40
- const c = [], a = /* @__PURE__ */ new Set(), s = (l) => {
41
- Array.isArray(l) && l.forEach((e) => {
42
- const n = [...e.children ?? [], ...e.select_items ?? []];
43
- if (n.length > 0) {
44
- s(n);
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 = e.text || e.tag_text;
48
- u && e.value && !a.has(e.value) && (a.add(e.value), c.push({ text: u, value: e.value }));
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
- }, [r] = Object.values(t ?? {});
51
- return s(r), c;
52
- }, i = (t, c, a = !1) => {
53
- const s = new Set(t.map((l) => l.value)), r = c.filter((l) => s.has(l.value) ? !1 : (s.add(l.value), !0));
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
- ...f(t, a),
56
- ...f(r, a)
58
+ ...i(t, a),
59
+ ...i(s, a)
57
60
  ];
58
- }, v = () => {
61
+ }, F = () => {
59
62
  var t;
60
63
  return ((t = document.head.querySelector('meta[name="csrf-token"]')) == null ? void 0 : t.getAttribute("content")) ?? "";
61
- }, k = (t) => typeof t == "string" ? t : typeof t == "number" ? String(t) : "";
64
+ }, T = (t) => typeof t == "string" ? t : typeof t == "number" ? String(t) : "";
62
65
  export {
63
- k as asText,
64
- i as buildMergeTagEntries,
65
- f as dynamicContentToMergeTags,
66
- b as flattenDynamicContentList,
67
- v as getCsrfToken,
68
- o as mergeTagToDynamicContent
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.d542b1f",
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",