UNPKG

@adyen/adyen-platform-experience-web

Version:

![Platform Experience header](https://github.com/Adyen/adyen-platform-experience-web/assets/7926613/18094965-9e01-450e-8dc9-ea84e6b22c2b)

184 lines (183 loc) 8.02 kB
var it = Object.defineProperty; var Y = (s) => { throw TypeError(s); }; var st = (s, r, t) => r in s ? it(s, r, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[r] = t; var P = (s, r, t) => st(s, typeof r != "symbol" ? r + "" : r, t), v = (s, r, t) => r.has(s) || Y("Cannot " + t); var i = (s, r, t) => (v(s, r, "read from private field"), t ? t.call(s) : r.get(s)), f = (s, r, t) => r.has(s) ? Y("Cannot add the same private member more than once") : r instanceof WeakSet ? r.add(s) : r.set(s, t), p = (s, r, t, e) => (v(s, r, "write to private field"), e ? e.call(s, t) : r.set(s, t), t), l = (s, r, t) => (v(s, r, "access private method"), t); import rt from "./TimeFrame.js"; import { getWeekendDays as G } from "../common/utils.js"; import { getEdgesDistance as Z, withTimezone as X, getTimezoneDateParts as k, computeTimestampOffset as ot, getMonthDays as x, startOfMonth as nt, startOfWeek as mt } from "../../utils.js"; import { DAY_MS as j, DAY_OF_WEEK_FORMATS as at, MAXIMUM_MONTH_UNITS as q } from "../../constants.js"; import ht from "../common/flags.js"; import { TimeFlag as m } from "../../types.js"; import { timezoneToSystem as J, systemToTimezone as Q } from "../../../../../../core/Localization/datetime/restamper/utils.js"; import { isUndefined as ft, isString as ct } from "../../../../../../utils/value/is.js"; import { isInfinity as lt, isBitSafeInteger as gt } from "../../../../../../utils/value/number.js"; import { enumerable as U } from "../../../../../../utils/struct/property.js"; import { struct as A, withFreezeProxyHandlers as ut, structFrom as pt } from "../../../../../../utils/struct/main.js"; var y, D, S, _, E, O, M, F, R, N, B, W, o, $, b, I, L; class Wt extends rt { constructor() { super(); f(this, o); f(this, y, 7); f(this, D, []); f(this, S, G(this.firstWeekDay)); f(this, _); f(this, E, -1 / 0); f(this, O, 1 / 0); f(this, M, 1 / 0); f(this, F); f(this, R); f(this, N); f(this, B); f(this, W); P(this, "daysInWeek", i(this, y)); this.initialize(); } get fromTimestamp() { return i(this, E); } get toTimestamp() { return i(this, O); } get numberOfBlocks() { return i(this, M); } get currentDayTimestamp() { return i(this, _); } get dynamicBlockHeight() { return super.dynamicBlockHeight; } set dynamicBlockHeight(t) { const e = this.dynamicBlockHeight; super.dynamicBlockHeight = t, this.dynamicBlockHeight !== e && this.refreshFrame(!0); } get rowspan() { return i(this, y); } get firstWeekDay() { return super.firstWeekDay; } set firstWeekDay(t) { const e = this.firstWeekDay; super.firstWeekDay = t, this.firstWeekDay !== e && (i(this, D).length = 0, p(this, S, G(this.firstWeekDay)), this.reoriginate(), this.refreshFrame()); } getCursorBlockOriginTimestampOffset(t) { return k(t, this.timezone)[2] - 1; } getDayOfWeekAtIndex(t) { if (!i(this, D)[t]) { const e = new Date(this.getTimestampAtIndex(t)); let n = 0; i(this, S).includes(t) && (n |= m.WEEKEND), t === 0 ? n |= m.LINE_START : t === 6 && (n |= m.LINE_END); const g = {}; for (const c of at) g[c] = U( e.toLocaleDateString(this.locale, { weekday: c, timeZone: this.timezone }) ); i(this, D)[t] = A({ flags: U(ht(n)), labels: U(A(g)) }); } return i(this, D)[t]; } getEdgeBlockOffsetsFromOrigin() { return [l(this, o, $).call(this, i(this, E)), l(this, o, $).call(this, i(this, O))]; } getFormattedDataForBlockCell(t) { const [e, n, g] = k(t, this.timezone); return [Number(g).toLocaleString(this.locale), `${e}-${`${n + 1}`.padStart(2, "0")}-${`${g}`.padStart(2, "0")}`]; } getFormattedDataForFrameBlock(t) { const [e, n] = k(t, this.timezone); return [ new Date(t).toLocaleDateString(this.locale, { month: "long", year: "numeric", timeZone: this.timezone }), `${e}-${`${n + 1}`.padStart(2, "0")}` ]; } getFrameBlockAtIndex(t) { const [e, n, g] = x(this.origin, i(this, N), t), c = t > 0 ? this.getFrameBlockAtIndex(t - 1).inner.to + 1 : i(this, F), a = c + e - 1, u = Math.floor(c / 7) * 7, z = this.dynamicBlockHeight ? Math.ceil((a + 1) / 7) * 7 : u + q, K = this.dynamicBlockHeight ? z - u : q, V = new Proxy( A(), ut({ get: (tt, w, et) => { if (ct(w)) { const H = +w; if (gt(H) && H >= 0 && H < K) { const d = u + H, T = this.getTimestampAtIndex(d), C = d % i(this, y); let h = T === this.currentDayTimestamp ? m.CURRENT : 0; return d === this.cursor && (h |= m.CURSOR), i(this, S).includes(C) && (h |= m.WEEKEND), C === 0 ? h |= m.LINE_START : C === i(this, y) - 1 && (h |= m.LINE_END), d >= c && d <= a && (d === c ? h |= m.BLOCK_START : d === a && (h |= m.BLOCK_END), h |= m.WITHIN_BLOCK), T >= this.fromTimestamp && T <= this.toTimestamp && (T === this.fromTimestamp && (h |= m.RANGE_START), T === this.toTimestamp && (h |= m.RANGE_END), h |= m.WITHIN_RANGE), T >= i(this, B) && T <= i(this, W) && (T === i(this, B) && (h |= m.SELECTION_START), T === i(this, W) && (h |= m.SELECTION_END), h |= m.WITHIN_SELECTION), [T, h]; } } return Reflect.get(tt, w, et); } }) ); return pt(V, { inner: { value: A({ from: { value: c }, to: { value: a }, units: { value: e } }) }, month: { value: n }, outer: { value: A({ from: { value: u }, to: { value: z - 1 }, units: { value: K } }) }, year: { value: g } }); } getUnitsForFrameBlockAtIndex(t) { return x(this.origin, i(this, N), t)[0]; } getUnitsOffsetForTimestamp(t, e) { return Math.round((e - t) / j); } reoriginate() { this.originTimestamp = nt(this.originTimestamp, this.timezone); const [t, e] = k(this.originTimestamp, this.timezone), n = mt(this.originTimestamp, this.timezone, this.firstWeekDay); this.origin = e, p(this, N, t), p(this, F, this.getUnitsOffsetForTimestamp(n, this.originTimestamp)), p(this, R, l(this, o, b).call(this, this.originTimestamp, -i(this, F))); } reslice() { l(this, o, L).call(this), p(this, E, l(this, o, I).call(this, super.fromTimestamp)), p(this, O, l(this, o, I).call(this, super.toTimestamp)), p(this, M, Z(super.fromTimestamp, super.toTimestamp, this.timezone) + 1); } shiftOrigin(t) { const [e, n] = k(this.originTimestamp, this.timezone), [, g, c] = x(n, e, t), a = X(this.timezone), u = new Date(J(a, this.originTimestamp)).setFullYear(c, g); this.originTimestamp = Q(a, u), this.reoriginate(); } clearSelection() { super.clearSelection(), l(this, o, L).call(this), this.refreshFrame(!0); } getTimestampAtIndex(t) { return l(this, o, b).call(this, i(this, R), t); } updateSelection(t, e) { super.updateSelection(t, e), l(this, o, L).call(this), this.refreshFrame(!0); } withCurrentDayTimestamp() { p(this, _, l(this, o, I).call(this, Date.now())); } } y = new WeakMap(), D = new WeakMap(), S = new WeakMap(), _ = new WeakMap(), E = new WeakMap(), O = new WeakMap(), M = new WeakMap(), F = new WeakMap(), R = new WeakMap(), N = new WeakMap(), B = new WeakMap(), W = new WeakMap(), o = new WeakSet(), $ = function(t) { const e = Z(t, this.originTimestamp, this.timezone); return t < this.originTimestamp ? 0 - e : e; }, b = function(t, e = 0) { const n = X(this.timezone), g = J(n, t), c = Q(n, g + e * j); let [, , , a, u] = k(c, this.timezone), z = 0; return (a > 0 || u > 0) && (a = (a > 12 ? 24 : 0) - a, u = (a > 1 ? 1 : -1) * u, z = a * 36e5 + u * 6e4), c + z; }, I = function(t) { return ft(t) || lt(t) ? t : t - ot(t, this.timezone); }, L = function() { p(this, B, l(this, o, I).call(this, this.selectionStart)), p(this, W, l(this, o, I).call(this, this.selectionEnd)); }; export { Wt as default };