@adyen/adyen-platform-experience-web
Version:

429 lines (428 loc) • 19.1 kB
JavaScript
var qt = Object.defineProperty;
var At = (m) => {
throw TypeError(m);
};
var Jt = (m, i, e) => i in m ? qt(m, i, { enumerable: !0, configurable: !0, writable: !0, value: e }) : m[i] = e;
var St = (m, i, e) => Jt(m, typeof i != "symbol" ? i + "" : i, e), Et = (m, i, e) => i.has(m) || At("Cannot " + e);
var t = (m, i, e) => (Et(m, i, "read from private field"), e ? e.call(m) : i.get(m)), c = (m, i, e) => i.has(m) ? At("Cannot add the same private member more than once") : i instanceof WeakSet ? i.add(m) : i.set(m, e), h = (m, i, e, r) => (Et(m, i, "write to private field"), r ? r.call(m, e) : i.set(m, e), e), f = (m, i, e) => (Et(m, i, "access private method"), e);
import { InteractionKeyCode as C } from "../../../../types.js";
import { SELECT_NONE as Q, CALENDAR_CONTROLS as Dt, SHIFT_BLOCK as Zt, SHIFT_PERIOD as Ot, SHIFT_FRAME as $t, CALENDAR_SELECTIONS as vt, SELECT_MANY as z, FRAME_SIZES as Qt, FIRST_WEEK_DAYS as ti, CURSOR_NEXT_BLOCK as ii, CURSOR_PREV_BLOCK as si, CURSOR_BLOCK_END as ei, CURSOR_LINE_END as hi, CURSOR_BLOCK_START as ri, CURSOR_LINE_START as ni, CURSOR_DOWNWARD as oi, CURSOR_UPWARD as ai, CURSOR_FORWARD as ci, CURSOR_BACKWARD as li, SELECT_ONE as tt, SELECTION_FROM as R, SELECTION_TO as D, CONTROLS_NONE as fi, CONTROLS_MINIMAL as ui, CONTROLS_ALL as mi, SELECTION_COLLAPSE as di } from "../constants.js";
import { withTimezone as Rt } from "../utils.js";
import { CalendarShiftControlsFlag as It, CalendarShiftControlFlag as Y } from "../types.js";
import { today as Lt } from "../../../../../primitives/time/today/main.js";
import { createIndexed as gt } from "../../../../../primitives/auxiliary/indexed/main.js";
import { createWatchlist as Si, isWatchlistUnsubscribeToken as Ei } from "../../../../../primitives/reactive/watchlist/main.js";
import { pickFrom as j } from "../../../../../utils/collection/main.js";
import { boolify as V, boolOrTrue as _t } from "../../../../../utils/value/bool.js";
import { createEffectStack as Ht } from "../../../../../primitives/reactive/effectStack/main.js";
import Oi from "../timeframe/frames/MonthFrame.js";
import { timezoneToSystem as it, systemToTimezone as st } from "../../../../../core/Localization/datetime/restamper/utils.js";
import { EMPTY_OBJECT as G } from "../../../../../utils/value/constants.js";
import { withFreezeProxyHandlers as Ri, structFrom as gi, struct as Ci } from "../../../../../utils/struct/main.js";
import { isNullish as et, isFunction as H, isString as wt, isUndefined as Wt } from "../../../../../utils/value/is.js";
import { noop as Mt } from "../../../../../utils/common.js";
import { isBitSafeInteger as Ti } from "../../../../../utils/value/number.js";
var Bt, Kt, u, y, s, N, T, A, O, P, g, K, L, _, p, I, U, J, w, k, nt, W, x, B, Z, ot, at, ct, lt, ft, ut, mt, F, Ut, xt, zt, dt, ht, n, X, Ct, Yt, jt, Vt, Gt, Tt, Xt, q, pt, rt, kt, Ft, bt, yt;
const d = class d {
constructor() {
c(this, n);
St(this, "grid");
St(this, "kill");
c(this, u, G);
c(this, y, !1);
c(this, s);
c(this, N);
c(this, T);
c(this, A, !1);
c(this, O, Q);
c(this, P, !1);
c(this, g);
c(this, K, (Bt = t(this, g)) == null ? void 0 : Bt.join(" "));
c(this, L);
c(this, _);
c(this, p);
c(this, I);
c(this, U);
c(this, J, Lt());
c(this, w, []);
c(this, k);
c(this, nt, new Proxy(
gt(() => {
var i;
return ((i = t(this, k)) == null ? void 0 : i.length) ?? 0;
}, f(this, n, Tt).bind(this)),
Ri({
get: (i, e, r) => {
var o, l;
const a = ((o = t(this, k)) == null ? void 0 : o.indexOf(e)) ?? -1;
return a >= 0 ? (l = f(this, n, Tt).call(this, a)) == null ? void 0 : l[1] : Reflect.get(i, e, r);
}
})
));
c(this, W, Si({
blocks: () => {
var i;
return (i = t(this, s)) == null ? void 0 : i.size;
},
cells: () => {
var i;
return (i = t(this, s)) == null ? void 0 : i.units;
},
controls: () => j(Dt, t(this, u).controls),
cursor: () => {
var i;
return (i = t(this, s)) == null ? void 0 : i.cursor;
},
from: () => {
var i;
return (i = t(this, s)) == null ? void 0 : i.selectionStart;
},
highlight: () => t(this, O),
locale: () => {
var i;
return (i = t(this, s)) == null ? void 0 : i.locale;
},
minified: () => V(t(this, u).minified),
origin: () => {
var i;
return (i = t(this, s)) == null ? void 0 : i.getTimestampAtIndex(0);
},
timezone: () => {
var i;
return (i = t(this, s)) == null ? void 0 : i.timezone;
},
to: () => {
var i;
return (i = t(this, s)) == null ? void 0 : i.selectionEnd;
},
today: () => t(this, J).timestamp
}));
c(this, x, (Kt = t(this, W)) == null ? void 0 : Kt.snapshot);
c(this, B, Ht(() => {
var i;
return t(this, p) && ((i = t(this, W)) == null ? void 0 : i.requestNotification());
}));
c(this, Z, Ht(() => {
var i;
return (i = t(this, p)) == null ? void 0 : i.call(t(this, n, X));
}));
c(this, ot, gi(
gt(
() => {
var i;
return ((i = t(this, s)) == null ? void 0 : i.size) ?? 0;
},
(i) => {
var e;
return (e = t(this, s)) == null ? void 0 : e.frameBlocks[i];
}
),
{
config: {
value: Object.defineProperties(
(i) => (i && f(this, n, jt).call(this, i), t(this, n, X)),
{
cursorIndex: {
get: () => t(this, L),
set: (i) => {
t(this, y) || (et(i) ? h(this, L, void 0) : H(i) && h(this, L, i));
}
},
shiftFactor: {
get: () => t(this, _),
set: (i) => {
t(this, y) || (et(i) ? h(this, _, void 0) : H(i) && h(this, _, i));
}
},
watch: {
get: () => t(this, p),
set: (i) => {
var e, r, a, o, l;
if (!t(this, y))
if (H(i)) {
if (h(this, p, i), !t(this, I)) {
const S = (e = t(this, B)) == null ? void 0 : e.bind(t(d, dt).bind(this));
S && (h(this, I, (r = t(this, B)) == null ? void 0 : r.bind(Mt)), h(this, U, (o = t(this, W)) == null ? void 0 : o.subscribe((a = t(this, Z)) == null ? void 0 : a.bind(S))), t(this, s) && (t(this, s).effect = t(this, I)));
}
if (!t(this, P)) return;
h(this, P, !1), (l = t(this, I)) == null || l.call(this);
} else et(i) && h(this, p, void 0);
}
}
}
)
},
controls: { value: t(this, nt) },
cursor: {
value: Object.defineProperties(
(i) => f(d, F, ht).call(this, (e) => !!(e && f(this, n, Vt).call(this, e)))(i),
{
valueOf: { value: () => {
var i;
return ((i = t(this, s)) == null ? void 0 : i.cursor) ?? -1;
} }
}
)
},
highlight: {
value: (() => {
const i = () => t(this, N) === t(this, T) && Wt(t(this, T)), e = (r) => (a) => f(d, F, ht).call(this, (o) => {
var l, S, E, b, M;
if (!(t(this, y) || !t(this, O) || t(this, O) === Q)) {
if (et(o)) return f(this, n, pt).call(this);
i() ? (S = t(this, s)) == null || S.updateSelection(o, di) : ((l = t(this, s)) == null || l.updateSelection(o, r), t(this, O) === z && t(this, g) && f(this, n, rt).call(this, o, r === R ? D : R, t(this, g))), h(this, N, (E = t(this, s)) == null ? void 0 : E.selectionStart), h(this, T, (b = t(this, s)) == null ? void 0 : b.selectionEnd), (M = t(this, s)) == null || M.shiftFrameToTimestamp(r === R ? t(this, N) : t(this, T));
}
})(a);
return Ci({
blank: { get: i },
from: {
get: () => {
var r;
return ((r = t(this, s)) == null ? void 0 : r.selectionStart) ?? t(this, N);
},
set: e(R)
},
to: {
get: () => {
var r;
return ((r = t(this, s)) == null ? void 0 : r.selectionEnd) ?? t(this, T);
},
set: e(D)
}
});
})()
},
rowspan: { get: () => {
var i;
return ((i = t(this, s)) == null ? void 0 : i.rowspan) ?? 0;
} },
weekdays: { get: () => {
var i;
return ((i = t(this, s)) == null ? void 0 : i.daysOfWeek) ?? t(d, lt);
} }
}
));
this.grid = t(this, ot), this.kill = f(this, n, Gt).bind(this);
}
};
u = new WeakMap(), y = new WeakMap(), s = new WeakMap(), N = new WeakMap(), T = new WeakMap(), A = new WeakMap(), O = new WeakMap(), P = new WeakMap(), g = new WeakMap(), K = new WeakMap(), L = new WeakMap(), _ = new WeakMap(), p = new WeakMap(), I = new WeakMap(), U = new WeakMap(), J = new WeakMap(), w = new WeakMap(), k = new WeakMap(), nt = new WeakMap(), W = new WeakMap(), x = new WeakMap(), B = new WeakMap(), Z = new WeakMap(), ot = new WeakMap(), at = new WeakMap(), ct = new WeakMap(), lt = new WeakMap(), ft = new WeakMap(), ut = new WeakMap(), mt = new WeakMap(), F = new WeakSet(), Ut = function(i) {
if (!wt(i) || !t(d, at).test(i)) return;
const e = i.split(/\s+/);
return Array.from({ length: 6 }, (r, a) => parseInt(e[a] ?? "0"));
}, xt = function(i) {
switch (i & ~Y.PREV) {
case Y.FRAME:
return $t;
case Y.PERIOD:
return Ot;
case Y.BLOCK:
default:
return Zt;
}
}, zt = function(i) {
return i & Y.PREV ? -1 : 1;
}, dt = new WeakMap(), ht = function(i) {
var e;
return ((e = t(this, B)) == null ? void 0 : e.bind(i)) ?? i;
}, n = new WeakSet(), X = function() {
return { ...t(this, u) };
}, Ct = function() {
return new Oi();
}, Yt = function(i) {
return !!t(this, s) && !(i > 0 ? t(this, s).isAtEnd : t(this, s).isAtStart);
}, jt = function(i) {
var a, o;
if (t(this, y)) return;
h(this, g, void 0);
const e = i == null ? void 0 : i.highlight, r = V(t(this, u).minified);
if (wt(e) ? h(this, g, f(a = d, F, Ut).call(a, e)) && h(this, O, z) : h(this, O, j(vt, e, t(this, O))), h(this, u, {
...t(this, u),
...i,
blocks: j(Qt, i == null ? void 0 : i.blocks, t(this, u).blocks),
controls: j(Dt, i == null ? void 0 : i.controls, t(this, u).controls),
firstWeekDay: j(ti, i == null ? void 0 : i.firstWeekDay, t(this, u).firstWeekDay),
fixedBlockHeight: V(i == null ? void 0 : i.fixedBlockHeight, t(this, u).fixedBlockHeight),
highlight: t(this, O),
minified: V(i == null ? void 0 : i.minified, t(this, u).minified),
trackCurrentDay: V(i == null ? void 0 : i.trackCurrentDay, t(this, u).trackCurrentDay)
}), !H(t(this, p))) {
t(this, s) ? h(this, P, !0) : (h(this, s, t(this, n, Ct)), f(this, n, Ft).call(this), f(this, n, yt).call(this), f(this, n, bt).call(this));
return;
}
(!t(this, s) || r !== t(this, u).minified) && (h(this, s, t(this, n, Ct)), t(this, s).effect = t(this, I)), f(this, n, Ft).call(this), (o = t(this, I)) == null || o.call(this);
}, Vt = function(i) {
if (i && t(this, s) && H(t(this, p))) {
if (i instanceof KeyboardEvent) {
switch (i.code) {
case C.ARROW_LEFT:
t(this, s).shiftFrameCursor(li);
break;
case C.ARROW_RIGHT:
t(this, s).shiftFrameCursor(ci);
break;
case C.ARROW_UP:
t(this, s).shiftFrameCursor(ai);
break;
case C.ARROW_DOWN:
t(this, s).shiftFrameCursor(oi);
break;
case C.HOME:
t(this, s).shiftFrameCursor(i.ctrlKey ? ri : ni);
break;
case C.END:
t(this, s).shiftFrameCursor(i.ctrlKey ? ei : hi);
break;
case C.PAGE_UP:
i.shiftKey ? t(this, s).shiftFrameByOffset(-1, Ot) : t(this, s).shiftFrameCursor(si);
break;
case C.PAGE_DOWN:
i.shiftKey ? t(this, s).shiftFrameByOffset(1, Ot) : t(this, s).shiftFrameCursor(ii);
break;
case C.SPACE:
case C.ENTER:
return f(this, n, q).call(this), !0;
default:
return;
}
return t(this, A) && f(this, n, q).call(this, G), !0;
}
if (i instanceof MouseEvent && t(d, ct).includes(i.type) && H(t(this, L))) {
const e = t(this, L).call(t(this, n, X), i);
if (!Ti(e)) return;
const r = i.type === "click";
if (!(r || t(this, A))) return;
if (t(this, s).shiftFrameCursor(e), t(this, s).cursor === e)
return r ? f(this, n, q).call(this) : f(this, n, q).call(this, G), !0;
}
}
}, Gt = function() {
var i;
t(this, y) || ((i = t(this, U)) == null || i.call(this), h(this, B, h(this, Z, h(this, L, h(this, s, h(this, O, h(this, K, h(this, x, h(this, g, h(this, _, h(this, U, h(this, W, h(this, I, h(this, p, void 0))))))))))))), h(this, u, G), h(this, A, h(this, P, !1)), h(this, y, !0));
}, Tt = function(i) {
var r, a;
if (!t(this, k) || i < 0 || i >= t(this, k).length) return;
const e = t(this, k)[i];
if (!t(this, w)[i]) {
const o = It[e], l = f(r = d, F, xt).call(r, o), S = f(a = d, F, zt).call(a, o);
t(this, w)[i] = (...E) => f(d, F, ht).call(this, (...b) => {
var v;
const M = f(this, n, Yt).call(this, S);
if (!(M && b.length)) return M;
const $ = f(this, n, Xt).call(this, e, b[0]);
return Wt($) ? !1 : ((v = t(this, s)) == null || v.shiftFrameByOffset(S * $, l), !0);
})(...E);
}
return [e, t(this, w)[i]];
}, Xt = function(i, e) {
if (!(t(this, s) && H(t(this, p)))) return;
if (e instanceof MouseEvent) {
if (e.type !== "click") return;
} else if (e instanceof KeyboardEvent) {
if (!t(d, ft).includes(e.code)) return;
} else return;
let r = 1;
if (H(t(this, _))) {
const a = Number(t(this, _).call(t(this, n, X), e, i));
r = Number.isInteger(a) && a >= 1 ? a : r;
}
return r;
}, q = function(i) {
if (t(this, y) || !t(this, s)) return;
switch (t(this, O)) {
case z:
case tt:
break;
case Q:
default:
return;
}
const e = t(this, s).cursor, r = Math.max(t(this, s).getTimestampAtIndex(e), t(this, s).timeslice.from), a = Math.min(t(this, s).getTimestampAtIndex(e + 1) - 1, t(this, s).timeslice.to), o = t(this, g);
if (t(this, O) === tt || t(this, s).blankSelection || o)
if (h(this, A, !(t(this, O) === tt || o)), t(this, O) === z && o) {
const l = a >= t(this, s).selectionEnd ? R : D;
l === R ? t(this, s).updateSelection(a, D) : t(this, s).updateSelection(r, R), f(this, n, rt).call(this, l === R ? t(this, s).selectionEnd : t(this, s).selectionStart, l, o);
} else
t(this, s).updateSelection(r, R), t(this, s).updateSelection(a, D);
else {
const l = i === G, S = Rt(t(this, s).timezone);
if (l || h(this, A, !1), r <= t(this, s).selectionStart) {
const E = new Date(it(S, t(this, s).selectionStart)), b = Math.min(
st(S, E.setDate(E.getDate() + 1) - 1),
t(this, s).timeslice.to
);
r === t(this, s).selectionStart && a <= b && t(this, s).updateSelection(a, D), t(this, s).updateSelection(r, R);
} else {
const E = new Date(it(S, t(this, s).selectionEnd)), b = Math.max(
st(S, E.setHours(0, 0, 0, 0)),
t(this, s).timeslice.from
);
r <= t(this, s).selectionEnd && r >= b && t(this, s).updateSelection(r, R), t(this, s).updateSelection(a, D);
}
if (l) return;
}
h(this, N, t(this, s).selectionStart), h(this, T, t(this, s).selectionEnd);
}, pt = function() {
var i;
(i = t(this, s)) == null || i.clearSelection(), h(this, A, !1), h(this, N, h(this, T, void 0));
}, rt = function(i, e, r) {
var Nt;
if (!t(this, s)) return;
const a = Rt((Nt = t(this, s)) == null ? void 0 : Nt.timezone), o = new Date(it(a, i)), l = e === R ? -1 : 1, [S = 0, E = 0, b = 0, M = 0, $ = 0, v = 0] = r ?? [];
o.setFullYear(
o.getFullYear() + S * l,
o.getMonth() + E * l,
o.getDate() + b * l
), o.setHours(
o.getHours() + M * l,
o.getMinutes() + $ * l,
o.getSeconds() + v * l
), t(this, s).updateSelection(st(a, o.getTime() - l), e);
}, kt = function() {
var i, e;
t(this, N) && ((i = t(this, s)) == null || i.updateSelection(t(this, N), R)), t(this, T) && ((e = t(this, s)) == null || e.updateSelection(t(this, T), D)), h(this, A, !1);
}, Ft = function() {
t(this, s) && (t(this, s).timeslice = t(this, u).timeslice, t(this, s).dynamicBlockHeight = !t(this, u).fixedBlockHeight, t(this, s).firstWeekDay = t(this, u).firstWeekDay, t(this, s).locale = t(this, u).locale, t(this, s).size = t(this, u).blocks, t(this, s).timezone = t(this, u).timezone, t(this, s).trackCurrentDay = t(this, u).trackCurrentDay, h(this, J, Lt(t(this, s).timezone)), f(this, n, kt).call(this));
}, bt = function() {
var i, e, r, a, o, l;
switch (t(this, O)) {
case z:
!_t((i = t(this, s)) == null ? void 0 : i.blankSelection) && t(this, g) && f(this, n, rt).call(this, (e = t(this, s)) == null ? void 0 : e.selectionStart, D, t(this, g));
break;
case tt:
if (!_t((r = t(this, s)) == null ? void 0 : r.blankSelection)) {
const S = Rt((a = t(this, s)) == null ? void 0 : a.timezone), E = new Date(it(S, (o = t(this, s)) == null ? void 0 : o.selectionStart));
(l = t(this, s)) == null || l.updateSelection(st(S, E.setHours(23, 59, 59, 999)), D);
}
break;
case Q:
default:
f(this, n, pt).call(this);
return;
}
}, yt = function() {
var i, e;
switch ((i = t(this, W)) == null ? void 0 : i.snapshot.controls) {
case mi:
h(this, k, t(d, ut));
break;
case ui:
h(this, k, t(d, mt));
break;
case fi:
default:
h(this, k, void 0);
}
t(this, w).length = 0, t(this, w).length = ((e = t(this, k)) == null ? void 0 : e.length) ?? 0;
}, c(d, F), c(d, at, /^(?:0|[1-9]\d*)(\s+(?:0|[1-9]\d*)?){0,5}?$/), c(d, ct, ["click", "mouseover", "pointerover"]), c(d, lt, gt(0, Mt)), c(d, ft, [C.ENTER, C.SPACE]), c(d, ut, Object.keys(It).filter((i) => isNaN(+i))), c(d, mt, ["PREV", "NEXT"]), c(d, dt, function(i) {
var l, S;
if (Ei(i)) return;
let e = !1, r = !1, a = !1;
const o = (l = t(this, g)) == null ? void 0 : l.join(" ");
for (const E of Object.keys(i))
i[E] !== ((S = t(this, x)) == null ? void 0 : S[E]) && (E === "controls" ? e = !0 : E === "highlight" ? r = !0 : (E === "from" || E === "to") && (a = !0));
t(this, K) !== o && (h(this, K, o), r = !0), h(this, x, i), t(this, A) && !a && f(this, n, kt).call(this), e && f(this, n, yt).call(this), r && f(this, n, bt).call(this);
});
let Pt = d;
export {
Pt as default
};