Skip to content

Commit 2d7b8ed

Browse files
committed
feat(hooks): add support for React Native
affects: @datepicker-react/hooks, @datepicker-react/styled
1 parent 3145fc2 commit 2d7b8ed

4 files changed

Lines changed: 566 additions & 558 deletions

File tree

packages/hooks/lib/index.cjs.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2547,9 +2547,11 @@ function Te(t) {
25472547
E = U[1]
25482548
t.useEffect(function () {
25492549
return (
2550-
'undefined' != typeof window && window.addEventListener('keydown', q),
2550+
'undefined' != typeof window &&
2551+
window.addEventListener &&
2552+
window.addEventListener('keydown', q),
25512553
function () {
2552-
window.removeEventListener('keydown', q)
2554+
window.removeEventListener && window.removeEventListener('keydown', q)
25532555
}
25542556
)
25552557
})

packages/hooks/lib/index.esm.js

Lines changed: 53 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ function P(t, e) {
540540
var w = S(l, e)
541541
return n.getTime() >= d.getTime() ? r + 1 : n.getTime() >= w.getTime() ? r : r - 1
542542
}
543-
function Y(t, e, n) {
543+
function E(t, e, n) {
544544
h(2, arguments)
545545
var r = n || {},
546546
a = r.locale,
@@ -556,7 +556,7 @@ function Y(t, e, n) {
556556
g = (w < u ? 7 : 0) + c - d
557557
return s.setUTCDate(s.getUTCDate() + g), s
558558
}
559-
function E(t) {
559+
function Y(t) {
560560
h(1, arguments)
561561
var e = 1,
562562
n = m(t),
@@ -570,24 +570,24 @@ function N(t) {
570570
n = e.getUTCFullYear(),
571571
r = new Date(0)
572572
r.setUTCFullYear(n + 1, 0, 4), r.setUTCHours(0, 0, 0, 0)
573-
var a = E(r),
573+
var a = Y(r),
574574
i = new Date(0)
575575
i.setUTCFullYear(n, 0, 4), i.setUTCHours(0, 0, 0, 0)
576-
var o = E(i)
576+
var o = Y(i)
577577
return e.getTime() >= a.getTime() ? n + 1 : e.getTime() >= o.getTime() ? n : n - 1
578578
}
579579
function q(t) {
580580
h(1, arguments)
581581
var e = N(t),
582582
n = new Date(0)
583583
n.setUTCFullYear(e, 0, 4), n.setUTCHours(0, 0, 0, 0)
584-
var r = E(n)
584+
var r = Y(n)
585585
return r
586586
}
587587
function B(t) {
588588
h(1, arguments)
589589
var e = m(t),
590-
n = E(e).getTime() - q(e).getTime()
590+
n = Y(e).getTime() - q(e).getTime()
591591
return Math.round(n / 6048e5) + 1
592592
}
593593
function O(t, e) {
@@ -808,7 +808,7 @@ var vt = {
808808
},
809809
set: function (t, e, n, r) {
810810
var a = new Date(0)
811-
return a.setUTCFullYear(n, 0, 4), a.setUTCHours(0, 0, 0, 0), E(a)
811+
return a.setUTCFullYear(n, 0, 4), a.setUTCHours(0, 0, 0, 0), Y(a)
812812
},
813813
incompatibleTokens: [
814814
'G',
@@ -1023,7 +1023,7 @@ var vt = {
10231023
return e >= 1 && e <= 53
10241024
},
10251025
set: function (t, e, n, r) {
1026-
return E(
1026+
return Y(
10271027
(function (t, e) {
10281028
h(2, arguments)
10291029
var n = m(t),
@@ -1128,7 +1128,7 @@ var vt = {
11281128
return e >= 0 && e <= 6
11291129
},
11301130
set: function (t, e, n, r) {
1131-
return (t = Y(t, n, r)).setUTCHours(0, 0, 0, 0), t
1131+
return (t = E(t, n, r)).setUTCHours(0, 0, 0, 0), t
11321132
},
11331133
incompatibleTokens: ['D', 'i', 'e', 'c', 't', 'T'],
11341134
},
@@ -1172,7 +1172,7 @@ var vt = {
11721172
return e >= 0 && e <= 6
11731173
},
11741174
set: function (t, e, n, r) {
1175-
return (t = Y(t, n, r)).setUTCHours(0, 0, 0, 0), t
1175+
return (t = E(t, n, r)).setUTCHours(0, 0, 0, 0), t
11761176
},
11771177
incompatibleTokens: [
11781178
'y',
@@ -1232,7 +1232,7 @@ var vt = {
12321232
return e >= 0 && e <= 6
12331233
},
12341234
set: function (t, e, n, r) {
1235-
return (t = Y(t, n, r)).setUTCHours(0, 0, 0, 0), t
1235+
return (t = E(t, n, r)).setUTCHours(0, 0, 0, 0), t
12361236
},
12371237
incompatibleTokens: [
12381238
'y',
@@ -1653,16 +1653,16 @@ function xt(t, e, n, r) {
16531653
.match(yt),
16541654
P = []
16551655
for (T = 0; T < S.length; T++) {
1656-
var Y = S[T]
1657-
!o.useAdditionalWeekYearTokens && M(Y) && U(Y), !o.useAdditionalDayOfYearTokens && C(Y) && U(Y)
1658-
var E = Y[0],
1659-
N = vt[E]
1656+
var E = S[T]
1657+
!o.useAdditionalWeekYearTokens && M(E) && U(E), !o.useAdditionalDayOfYearTokens && C(E) && U(E)
1658+
var Y = E[0],
1659+
N = vt[Y]
16601660
if (N) {
16611661
var q = N.incompatibleTokens
16621662
if (Array.isArray(q)) {
16631663
for (var B = void 0, O = 0; O < P.length; O++) {
16641664
var H = P[O].token
1665-
if (-1 !== q.indexOf(H) || H === E) {
1665+
if (-1 !== q.indexOf(H) || H === Y) {
16661666
B = P[O]
16671667
break
16681668
}
@@ -1671,14 +1671,14 @@ function xt(t, e, n, r) {
16711671
throw new RangeError(
16721672
"The format string mustn't contain `"
16731673
.concat(B.fullToken, '` and `')
1674-
.concat(Y, '` at the same time'),
1674+
.concat(E, '` at the same time'),
16751675
)
16761676
} else if ('*' === N.incompatibleTokens && P.length)
16771677
throw new RangeError(
1678-
"The format string mustn't contain `".concat(Y, '` and any other token at the same time'),
1678+
"The format string mustn't contain `".concat(E, '` and any other token at the same time'),
16791679
)
1680-
P.push({token: E, fullToken: Y})
1681-
var L = N.parse(a, Y, u.match, k)
1680+
P.push({token: Y, fullToken: E})
1681+
var L = N.parse(a, E, u.match, k)
16821682
if (!L) return new Date(NaN)
16831683
x.push({
16841684
priority: N.priority,
@@ -1689,13 +1689,13 @@ function xt(t, e, n, r) {
16891689
}),
16901690
(a = L.rest)
16911691
} else {
1692-
if (E.match(kt))
1692+
if (Y.match(kt))
16931693
throw new RangeError(
1694-
'Format string contains an unescaped latin alphabet character `' + E + '`',
1694+
'Format string contains an unescaped latin alphabet character `' + Y + '`',
16951695
)
1696-
if (("''" === Y ? (Y = "'") : "'" === E && (Y = Mt(Y)), 0 !== a.indexOf(Y)))
1696+
if (("''" === E ? (E = "'") : "'" === Y && (E = Mt(E)), 0 !== a.indexOf(E)))
16971697
return new Date(NaN)
1698-
a = a.slice(Y.length)
1698+
a = a.slice(E.length)
16991699
}
17001700
}
17011701
if (a.length > 0 && pt.test(a)) return new Date(NaN)
@@ -1757,11 +1757,11 @@ var Pt = function (t, e) {
17571757
r = n > 0 ? n : 1 - n
17581758
return St('yy' === e ? r % 100 : r, e.length)
17591759
},
1760-
Yt = function (t, e) {
1760+
Et = function (t, e) {
17611761
var n = t.getUTCMonth()
17621762
return 'M' === e ? String(n + 1) : St(n + 1, 2)
17631763
},
1764-
Et = function (t, e) {
1764+
Yt = function (t, e) {
17651765
return St(t.getUTCDate(), e.length)
17661766
},
17671767
Nt = function (t, e) {
@@ -1866,7 +1866,7 @@ var Lt = 'midnight',
18661866
switch (e) {
18671867
case 'M':
18681868
case 'MM':
1869-
return Yt(t, e)
1869+
return Et(t, e)
18701870
case 'Mo':
18711871
return n.ordinalNumber(r + 1, {unit: 'month'})
18721872
case 'MMM':
@@ -1905,7 +1905,7 @@ var Lt = 'midnight',
19051905
return 'Io' === e ? n.ordinalNumber(r, {unit: 'week'}) : St(r, e.length)
19061906
},
19071907
d: function (t, e, n) {
1908-
return 'do' === e ? n.ordinalNumber(t.getUTCDate(), {unit: 'date'}) : Et(t, e)
1908+
return 'do' === e ? n.ordinalNumber(t.getUTCDate(), {unit: 'date'}) : Yt(t, e)
19091909
},
19101910
D: function (t, e, n) {
19111911
var r = (function (t) {
@@ -2519,8 +2519,8 @@ function Se(t) {
25192519
)
25202520
}
25212521
var Pe = 'startDate',
2522-
Ye = 'endDate'
2523-
function Ee(t) {
2522+
Ee = 'endDate'
2523+
function Ye(t) {
25242524
var r = t.startDate,
25252525
a = t.endDate,
25262526
i = t.focusedInput,
@@ -2555,20 +2555,22 @@ function Ee(t) {
25552555
U = C[1],
25562556
S = e(r),
25572557
P = S[0],
2558-
Y = S[1]
2558+
E = S[1]
25592559
n(function () {
25602560
return (
2561-
'undefined' != typeof window && window.addEventListener('keydown', B),
2561+
'undefined' != typeof window &&
2562+
window.addEventListener &&
2563+
window.addEventListener('keydown', B),
25622564
function () {
2563-
window.removeEventListener('keydown', B)
2565+
window.removeEventListener && window.removeEventListener('keydown', B)
25642566
}
25652567
)
25662568
})
2567-
var E = function (t) {
2569+
var Y = function (t) {
25682570
return ve(T, t) || b(t)
25692571
},
25702572
N = function (t) {
2571-
Y(t), (!P || (P && !we(t, P))) && x(Ce(w, t))
2573+
E(t), (!P || (P && !we(t, P))) && x(Ce(w, t))
25722574
},
25732575
q = function (t) {
25742576
return pe({
@@ -2578,7 +2580,7 @@ function Ee(t) {
25782580
startDate: r,
25792581
endDate: a,
25802582
minBookingDays: h,
2581-
isDateBlockedFn: E,
2583+
isDateBlockedFn: Y,
25822584
})
25832585
}
25842586
function B(t) {
@@ -2627,7 +2629,7 @@ function Ee(t) {
26272629
endDate: a,
26282630
minBookingDays: h,
26292631
exactMinBookingDays: l,
2630-
isDateBlocked: E,
2632+
isDateBlocked: Y,
26312633
})
26322634
},
26332635
isFirstOrLastSelectedDate: function (t) {
@@ -2675,52 +2677,52 @@ function Ee(t) {
26752677
exactMinBookingDays: l,
26762678
minBookingDate: o,
26772679
maxBookingDate: u,
2678-
isDateBlocked: E,
2680+
isDateBlocked: Y,
26792681
startDate: t,
26802682
endDate: null,
26812683
})
26822684
? s({startDate: t, endDate: te(t, h - 1), focusedInput: null})
26832685
: (('endDate' === i && r && le(t, r)) || ('startDate' === i && a && fe(t, a))) &&
26842686
!l &&
2685-
Se({minBookingDays: h, isDateBlocked: E, startDate: t, endDate: null})
2687+
Se({minBookingDays: h, isDateBlocked: Y, startDate: t, endDate: null})
26862688
? s({endDate: null, startDate: t, focusedInput: 'endDate'})
26872689
: 'startDate' === i &&
26882690
!l &&
2689-
Se({minBookingDays: h, isDateBlocked: E, endDate: a, startDate: t})
2691+
Se({minBookingDays: h, isDateBlocked: Y, endDate: a, startDate: t})
26902692
? s({endDate: a, startDate: t, focusedInput: 'endDate'})
26912693
: 'startDate' === i &&
26922694
!l &&
2693-
Se({minBookingDays: h, isDateBlocked: E, endDate: null, startDate: t})
2695+
Se({minBookingDays: h, isDateBlocked: Y, endDate: null, startDate: t})
26942696
? s({endDate: null, startDate: t, focusedInput: 'endDate'})
26952697
: 'endDate' === i &&
26962698
r &&
26972699
!le(t, r) &&
26982700
!l &&
2699-
Se({minBookingDays: h, isDateBlocked: E, startDate: r, endDate: t}) &&
2701+
Se({minBookingDays: h, isDateBlocked: Y, startDate: r, endDate: t}) &&
27002702
s({startDate: r, endDate: t, focusedInput: null}),
27012703
'endDate' === i || (P && (!P || we(t, P))) || x(Ce(w, t))
27022704
},
27032705
onDateFocus: N,
27042706
goToPreviousMonths: function () {
2705-
x(Me(k, w, -1)), Y(null)
2707+
x(Me(k, w, -1)), E(null)
27062708
},
27072709
goToPreviousMonthsByOneMonth: function () {
2708-
x(Me(k, w, -1, 1)), Y(null)
2710+
x(Me(k, w, -1, 1)), E(null)
27092711
},
27102712
goToNextMonths: function () {
2711-
x(Me(k, w, 1)), Y(null)
2713+
x(Me(k, w, 1)), E(null)
27122714
},
27132715
goToNextMonthsByOneMonth: function () {
2714-
x(Me(k, w, 1, 1)), Y(null)
2716+
x(Me(k, w, 1, 1)), E(null)
27152717
},
27162718
goToDate: function (t) {
2717-
x(Ce(w, t)), Y(null)
2719+
x(Ce(w, t)), E(null)
27182720
},
27192721
goToPreviousYear: function (t) {
2720-
void 0 === t && (t = 1), x(Me(k, w, -(12 * t - w + 1))), Y(null)
2722+
void 0 === t && (t = 1), x(Me(k, w, -(12 * t - w + 1))), E(null)
27212723
},
27222724
goToNextYear: function (t) {
2723-
void 0 === t && (t = 1), x(Me(k, w, 12 * t - w + 1)), Y(null)
2725+
void 0 === t && (t = 1), x(Me(k, w, 12 * t - w + 1)), E(null)
27242726
},
27252727
}
27262728
}
@@ -2768,7 +2770,7 @@ function Ne(t) {
27682770
}
27692771
}
27702772
export {
2771-
Ye as END_DATE,
2773+
Ee as END_DATE,
27722774
Pe as START_DATE,
27732775
ue as dayLabelFormat,
27742776
xe as getCurrentYearMonthAndDate,
@@ -2784,7 +2786,7 @@ export {
27842786
De as isStartDate,
27852787
ce as monthLabelFormat,
27862788
xt as parseDate,
2787-
Ee as useDatepicker,
2789+
Ye as useDatepicker,
27882790
Ne as useDay,
27892791
de as useMonth,
27902792
se as weekdayLabelFormat,

0 commit comments

Comments
 (0)