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)

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