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)

126 lines (125 loc) 3.55 kB
import { useState as J, useMemo as l, useRef as _, useCallback as G, useImperativeHandle as Q, useEffect as P } from "../../../../external/preact/hooks/dist/hooks.module.js"; import U from "../../../../core/Context/useCoreContext.js"; import { getDateObjectFromTimestamp as K } from "../calendar/utils.js"; import X from "../../../../hooks/element/useFocusCursor.js"; import n from "../calendar/facade/index.js"; import { EMPTY_OBJECT as u } from "../../../../utils/value/constants.js"; import { isFunction as L } from "../../../../utils/value/is.js"; const H = ({ blocks: f, controls: a, dynamicBlockRows: m, firstWeekDay: g, highlight: p, locale: N, onHighlight: s, originDate: w, renderControl: C, sinceDate: E, timezone: M, trackCurrentDay: T, untilDate: d, useYearView: b }, B) => { const { i18n: O } = U(), [R, S] = J(performance.now()), F = l(() => n.slice(E, d), [E, d]), I = _(u), x = l( () => a ?? (L(C) ? n.controls.MINIMAL : n.controls.NONE), [a, C] ), A = l( () => p ?? (L(s) ? n.highlight.ONE : n.highlight.NONE), [p, s] ), { grid: t, kill: j } = l(() => { const { grid: e, kill: r } = n(function() { S(performance.now()), I.current = this, !(o === e.highlight.from && h === e.highlight.to) && (o = e.highlight.from, h = e.highlight.to, s == null || s(o, h)); }); let { from: o, to: h } = e.highlight; return e.config.cursorIndex = (i) => { let c = i.target; for (; c && c !== i.currentTarget; ) { const k = Number(c.dataset.cursorPosition); if (Number.isFinite(k)) return k; c = c.parentNode; } }, e.config.shiftFactor = function(i) { if (this.controls === n.controls.MINIMAL) return i != null && i.shiftKey ? 12 : i != null && i.altKey ? this.blocks : 1; }, { grid: e, kill: r }; }, []), q = l(() => { const e = (r) => { t.cursor(r); }; return { onClickCapture: e, onMouseOverCapture: e, onPointerOverCapture: e, onKeyDownCapture: (r) => { t.cursor(r) && r.preventDefault(); } }; }, [t]), y = X( G( (e, r) => { r instanceof Element && r.removeAttribute("aria-selected"), e instanceof Element && e.setAttribute("aria-selected", "true"); }, [] ) ); return Q( B, () => { const { from: e, to: r } = (t == null ? void 0 : t.highlight) || u; return { clear: () => { t != null && t.highlight && (t.highlight.from = void 0); }, get config() { return { ...I.current ?? u }; }, get from() { return K(e); }, set from(o) { t != null && t.highlight && o && (t.highlight.from = o.getTime()); }, get to() { return K(r); }, set to(o) { t != null && t.highlight && o && (t.highlight.to = o.getTime()); } }; }, [t, R] ), P(() => { t.config({ blocks: f, controls: x, firstWeekDay: g, fixedBlockHeight: !m, highlight: A, locale: N ?? O.locale, minified: b, timeslice: F, timezone: M, trackCurrentDay: T }); }, [ x, A, f, m, g, t, O, N, F, M, T, b ]), P(() => { const e = [].concat(w).slice(0, 2).map(Number).filter(Boolean); return e[0] && (t.highlight.from = +e[0]), e[1] && (t.highlight.to = +e[1]), j; }, []), { cursorElementRef: y, cursorRootProps: q, grid: t }; }; export { H as default };