persian-date-kit 0.0.3 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +27 -0
- package/dist/PersianDatePicker-Bcz6VNVe.cjs +1 -0
- package/dist/PersianDatePicker-DFMNtlIF.js +1171 -0
- package/dist/components/PersianDatePicker.d.ts +3 -57
- package/dist/components/PersianDatePicker.d.ts.map +1 -1
- package/dist/components/PersianDateRangePicker.d.ts +4 -45
- package/dist/components/PersianDateRangePicker.d.ts.map +1 -1
- package/dist/components/_CalendarHeader.d.ts +17 -0
- package/dist/components/_CalendarHeader.d.ts.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +373 -261
- package/dist/react-hook-form.cjs +1 -1
- package/dist/react-hook-form.d.ts +4 -1
- package/dist/react-hook-form.d.ts.map +1 -1
- package/dist/react-hook-form.mjs +1 -1
- package/dist/styles.css +5 -0
- package/dist/types/shared.d.ts +120 -0
- package/dist/types/shared.d.ts.map +1 -0
- package/dist/utils/usePopoverPosition.d.ts +29 -0
- package/dist/utils/usePopoverPosition.d.ts.map +1 -0
- package/package.json +31 -2
- package/dist/PersianDatePicker-BicyzfQH.js +0 -1028
- package/dist/PersianDatePicker-CCakBpBo.cjs +0 -1
|
@@ -1,65 +1,11 @@
|
|
|
1
|
-
import
|
|
2
|
-
export type PersianDatePickerClasses = Partial<{
|
|
3
|
-
root: string;
|
|
4
|
-
input: string;
|
|
5
|
-
button: string;
|
|
6
|
-
popover: string;
|
|
7
|
-
header: string;
|
|
8
|
-
navButton: string;
|
|
9
|
-
monthLabel: string;
|
|
10
|
-
grid: string;
|
|
11
|
-
weekday: string;
|
|
12
|
-
day: string;
|
|
13
|
-
dayOutside: string;
|
|
1
|
+
import type { BasePickerProps, BasePickerClasses } from "../types/shared";
|
|
2
|
+
export type PersianDatePickerClasses = Partial<BasePickerClasses & {
|
|
14
3
|
daySelected: string;
|
|
15
|
-
dayDisabled: string;
|
|
16
|
-
dayToday: string;
|
|
17
4
|
}>;
|
|
18
|
-
export type PersianDatePickerProps = {
|
|
5
|
+
export type PersianDatePickerProps = BasePickerProps & {
|
|
19
6
|
value: Date | null;
|
|
20
7
|
onChange: (date: Date | null) => void;
|
|
21
|
-
minDate?: Date;
|
|
22
|
-
maxDate?: Date;
|
|
23
|
-
disabled?: boolean;
|
|
24
8
|
placeholder?: string;
|
|
25
|
-
/**
|
|
26
|
-
* Control the open state of the calendar popover.
|
|
27
|
-
* If provided, the component becomes controlled for open/close.
|
|
28
|
-
*/
|
|
29
|
-
open?: boolean;
|
|
30
|
-
onOpenChange?: (open: boolean) => void;
|
|
31
|
-
/**
|
|
32
|
-
* Rendering mode:
|
|
33
|
-
* - `popover`: default input + popover calendar
|
|
34
|
-
* - `inline`: always-visible calendar, no input
|
|
35
|
-
*/
|
|
36
|
-
mode?: 'popover' | 'inline';
|
|
37
|
-
/**
|
|
38
|
-
* Formats the controlled `value` for display in the input.
|
|
39
|
-
* Default: numeric Jalali `YYYY/MM/DD` (no locale month/day names).
|
|
40
|
-
*/
|
|
41
|
-
formatValue?: (date: Date) => string;
|
|
42
|
-
/**
|
|
43
|
-
* Parses user input into a Gregorian Date.
|
|
44
|
-
* Default: parses numeric Jalali `YYYY/MM/DD` (also accepts loose separators).
|
|
45
|
-
*/
|
|
46
|
-
parseValue?: (text: string) => Date | null;
|
|
47
|
-
/**
|
|
48
|
-
* Weekday headers. If omitted, numeric headers are used.
|
|
49
|
-
* Provide 7 items matching the calendar grid order.
|
|
50
|
-
*/
|
|
51
|
-
weekdays?: string[];
|
|
52
|
-
/**
|
|
53
|
-
* Month labels (index 0 => month 1). If omitted, month numbers are shown.
|
|
54
|
-
* Provide 12 items.
|
|
55
|
-
*/
|
|
56
|
-
monthLabels?: string[];
|
|
57
|
-
/**
|
|
58
|
-
* Month label renderer (e.g. supply localized month name).
|
|
59
|
-
* Default: `jy / jm` numeric.
|
|
60
|
-
*/
|
|
61
|
-
renderMonthLabel?: (jy: number, jm: number) => React.ReactNode;
|
|
62
|
-
className?: string;
|
|
63
9
|
classes?: PersianDatePickerClasses;
|
|
64
10
|
};
|
|
65
11
|
export declare function PersianDatePicker(props: PersianDatePickerProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PersianDatePicker.d.ts","sourceRoot":"","sources":["../../src/components/PersianDatePicker.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"PersianDatePicker.d.ts","sourceRoot":"","sources":["../../src/components/PersianDatePicker.tsx"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAE1E,MAAM,MAAM,wBAAwB,GAAG,OAAO,CAC5C,iBAAiB,GAAG;IAClB,WAAW,EAAE,MAAM,CAAC;CACrB,CACF,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG,eAAe,GAAG;IACrD,KAAK,EAAE,IAAI,GAAG,IAAI,CAAC;IACnB,QAAQ,EAAE,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,KAAK,IAAI,CAAC;IACtC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,wBAAwB,CAAC;CACpC,CAAC;AAmCF,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,sBAAsB,2CA6mB9D"}
|
|
@@ -1,67 +1,26 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { BasePickerProps, BasePickerClasses } from "../types/shared";
|
|
2
2
|
export type PersianDateRange = {
|
|
3
3
|
start: Date | null;
|
|
4
4
|
end: Date | null;
|
|
5
5
|
};
|
|
6
|
-
export type PersianDateRangePickerClasses = Partial<{
|
|
7
|
-
root: string;
|
|
8
|
-
input: string;
|
|
9
|
-
button: string;
|
|
10
|
-
popover: string;
|
|
11
|
-
header: string;
|
|
12
|
-
navButton: string;
|
|
13
|
-
monthLabel: string;
|
|
14
|
-
grid: string;
|
|
15
|
-
weekday: string;
|
|
16
|
-
day: string;
|
|
17
|
-
dayOutside: string;
|
|
18
|
-
dayDisabled: string;
|
|
19
|
-
dayToday: string;
|
|
6
|
+
export type PersianDateRangePickerClasses = Partial<BasePickerClasses & {
|
|
20
7
|
dayRangeStart: string;
|
|
21
8
|
dayRangeEnd: string;
|
|
22
9
|
dayInRange: string;
|
|
23
10
|
}>;
|
|
24
|
-
export type PersianDateRangePickerProps = {
|
|
11
|
+
export type PersianDateRangePickerProps = BasePickerProps & {
|
|
25
12
|
value: PersianDateRange;
|
|
26
13
|
onChange: (range: PersianDateRange) => void;
|
|
27
|
-
minDate?: Date;
|
|
28
|
-
maxDate?: Date;
|
|
29
|
-
disabled?: boolean;
|
|
30
14
|
/**
|
|
31
15
|
* Input layout:
|
|
32
16
|
* - `two`: (default) two inputs (start/end)
|
|
33
17
|
* - `single`: one input showing the range as text (e.g. `start - end`)
|
|
34
18
|
*/
|
|
35
|
-
inputVariant?:
|
|
19
|
+
inputVariant?: "two" | "single";
|
|
36
20
|
placeholder?: string;
|
|
37
21
|
rangeSeparator?: string;
|
|
38
22
|
placeholderStart?: string;
|
|
39
23
|
placeholderEnd?: string;
|
|
40
|
-
/**
|
|
41
|
-
* Control the open state of the calendar popover (popover mode only).
|
|
42
|
-
*/
|
|
43
|
-
open?: boolean;
|
|
44
|
-
onOpenChange?: (open: boolean) => void;
|
|
45
|
-
/**
|
|
46
|
-
* Rendering mode:
|
|
47
|
-
* - `popover`: (default) two inputs + popover calendar
|
|
48
|
-
* - `inline`: always-visible calendar, no inputs
|
|
49
|
-
*/
|
|
50
|
-
mode?: 'popover' | 'inline';
|
|
51
|
-
/**
|
|
52
|
-
* Formats a Date for display in inputs.
|
|
53
|
-
* Default: numeric Jalali `YYYY/MM/DD` (no locale month/day names).
|
|
54
|
-
*/
|
|
55
|
-
formatValue?: (date: Date) => string;
|
|
56
|
-
/**
|
|
57
|
-
* Parses user text into a Gregorian Date.
|
|
58
|
-
* Default: parses numeric Jalali `YYYY/MM/DD` (also accepts loose separators).
|
|
59
|
-
*/
|
|
60
|
-
parseValue?: (text: string) => Date | null;
|
|
61
|
-
weekdays?: string[];
|
|
62
|
-
monthLabels?: string[];
|
|
63
|
-
renderMonthLabel?: (jy: number, jm: number) => React.ReactNode;
|
|
64
|
-
className?: string;
|
|
65
24
|
classes?: PersianDateRangePickerClasses;
|
|
66
25
|
};
|
|
67
26
|
export declare function PersianDateRangePicker(props: PersianDateRangePickerProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PersianDateRangePicker.d.ts","sourceRoot":"","sources":["../../src/components/PersianDateRangePicker.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"PersianDateRangePicker.d.ts","sourceRoot":"","sources":["../../src/components/PersianDateRangePicker.tsx"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAE1E,MAAM,MAAM,gBAAgB,GAAG;IAC7B,KAAK,EAAE,IAAI,GAAG,IAAI,CAAC;IACnB,GAAG,EAAE,IAAI,GAAG,IAAI,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,6BAA6B,GAAG,OAAO,CACjD,iBAAiB,GAAG;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;CACpB,CACF,CAAC;AAEF,MAAM,MAAM,2BAA2B,GAAG,eAAe,GAAG;IAC1D,KAAK,EAAE,gBAAgB,CAAC;IACxB,QAAQ,EAAE,CAAC,KAAK,EAAE,gBAAgB,KAAK,IAAI,CAAC;IAC5C;;;;OAIG;IACH,YAAY,CAAC,EAAE,KAAK,GAAG,QAAQ,CAAC;IAChC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,OAAO,CAAC,EAAE,6BAA6B,CAAC;CACzC,CAAC;AAkCF,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,2BAA2B,2CAopBxE"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
export type CalendarHeaderProps = {
|
|
3
|
+
title: React.ReactNode;
|
|
4
|
+
onPrev: () => void;
|
|
5
|
+
onNext: () => void;
|
|
6
|
+
onTitleClick: () => void;
|
|
7
|
+
prevIcon?: React.ReactNode;
|
|
8
|
+
nextIcon?: React.ReactNode;
|
|
9
|
+
className?: string;
|
|
10
|
+
classes?: Partial<{
|
|
11
|
+
header: string;
|
|
12
|
+
navButton: string;
|
|
13
|
+
monthLabel: string;
|
|
14
|
+
}>;
|
|
15
|
+
};
|
|
16
|
+
export declare function CalendarHeader(props: CalendarHeaderProps): import("react/jsx-runtime").JSX.Element;
|
|
17
|
+
//# sourceMappingURL=_CalendarHeader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_CalendarHeader.d.ts","sourceRoot":"","sources":["../../src/components/_CalendarHeader.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,MAAM,MAAM,mBAAmB,GAAG;IAChC,KAAK,EAAE,KAAK,CAAC,SAAS,CAAC;IACvB,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,YAAY,EAAE,MAAM,IAAI,CAAC;IACzB,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC3B,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC3B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,OAAO,CAAC;QAChB,MAAM,EAAE,MAAM,CAAC;QACf,SAAS,EAAE,MAAM,CAAC;QAClB,UAAU,EAAE,MAAM,CAAC;KACpB,CAAC,CAAC;CACJ,CAAC;AAMF,wBAAgB,cAAc,CAAC,KAAK,EAAE,mBAAmB,2CAgCxD"}
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./PersianDatePicker-CCakBpBo.cjs"),o=require("react/jsx-runtime"),we=require("react");function Ne(d){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(d){for(const c in d)if(c!=="default"){const m=Object.getOwnPropertyDescriptor(d,c);Object.defineProperty(n,c,m.get?m:{enumerable:!0,get:()=>d[c]})}}return n.default=d,Object.freeze(n)}const i=Ne(we);function l(...d){return d.filter(Boolean).join(" ")}function Ce(d){return r.toJalali(d).formatted}function Ee(d){return r.parseJalaliText(d,{allowLooseSeparators:!0})}function b(){const d=new Date;return d.setHours(0,0,0,0),d}function $(d){const{start:n,end:c}=d;return n&&c&&r.compareDays(n,c)>0?{start:c,end:n}:d}function Te(d,n,c){const m=r.compareDays(n,c)<=0?n:c,j=r.compareDays(n,c)<=0?c:n;return r.compareDays(d,m)>=0&&r.compareDays(d,j)<=0}function $e(d){const{value:n,onChange:c,minDate:m,maxDate:j,disabled:P,inputVariant:W="two",placeholder:le,rangeSeparator:M=" - ",placeholderStart:ce,placeholderEnd:ue,open:G,onOpenChange:pe,mode:g="popover",formatValue:v=Ce,parseValue:L=Ee,weekdays:w,monthLabels:x,renderMonthLabel:O,className:fe,classes:p}=d,V=i.useRef(null),Y=i.useRef(null),U=i.useRef(null),I=i.useRef(null),q=i.useRef(null),[me,ye]=i.useState(!1),y=g==="inline"?!0:G??me;function A(e){pe?.(e),g!=="inline"&&G===void 0&&ye(e)}const[z,H]=i.useState("start"),[_,J]=i.useState("days"),[je,R]=i.useState(()=>{const e=n.start??n.end??b(),t=r.toJalaliParts(e).jy;return t-t%12}),[N,C]=i.useState(()=>{const e=n.start??n.end??b();return r.toJalaliParts(e).jy}),[u,S]=i.useState(()=>{const e=n.start??n.end??b(),t=r.toJalaliParts(e);return{jy:t.jy,jm:t.jm}}),[k,h]=i.useState(()=>n.start??n.end??b()),[K,Q]=i.useState(null),[X,Z]=i.useState(()=>n.start?v(n.start):""),[ee,te]=i.useState(()=>n.end?v(n.end):""),[ne,E]=i.useState(()=>{const e=n.start?v(n.start):"",t=n.end?v(n.end):"";return!e&&!t?"":e&&!t?`${e}${M}`:`${e}${M}${t}`});i.useEffect(()=>{Z(n.start?v(n.start):""),te(n.end?v(n.end):"");const e=n.start?v(n.start):"",t=n.end?v(n.end):"";E(!e&&!t?"":e&&!t?`${e}${M}`:`${e}${M}${t}`);const a=n.start??n.end??b(),s=r.toJalaliParts(a);S({jy:s.jy,jm:s.jm}),h(a),C(s.jy),R(s.jy-s.jy%12)},[v,n.end,n.start]),i.useEffect(()=>{if(g!=="popover"||!y)return;const e=t=>{const a=V.current;a&&t.target instanceof Node&&!a.contains(t.target)&&A(!1)};return document.addEventListener("pointerdown",e),()=>document.removeEventListener("pointerdown",e)},[g,y]),i.useEffect(()=>{y&&q.current?.focus()},[y]),i.useEffect(()=>{if(!y)return;const e=r.toJalaliParts(k);S(t=>t.jy===e.jy&&t.jm===e.jm?t:{jy:e.jy,jm:e.jm})},[k,y]);const ge=i.useMemo(()=>O?O(u.jy,u.jm):x&&x.length===12?`${x[u.jm-1]??String(u.jm)} ${u.jy}`:`${u.jy} / ${u.jm}`,[x,O,u.jm,u.jy]),ve=i.useMemo(()=>w&&w.length===7?w:["1","2","3","4","5","6","7"],[w]),he=i.useMemo(()=>r.buildJalaliMonthGrid({jy:u.jy,jm:u.jm}),[u.jm,u.jy]);function F(e){if(P)return;H(e),A(!0);const t=(e==="start"?n.start:n.end)??n.start??n.end??b(),a=r.toJalaliParts(t);S({jy:a.jy,jm:a.jm}),h(t),J("days"),C(a.jy),R(a.jy-a.jy%12)}function ae(){A(!1),J("days"),g==="popover"&&(W==="single"?Y.current?.focus():(z==="start"?U:I).current?.focus())}function re(e){return P?!0:!r.isWithinRange(e.gregorian,m,j)}function se(e,t){const a=t.trim();if(!a){const D=$({...n,[e]:null});c(D);return}const s=L(a);if(!s||!r.isWithinRange(s,m,j))return;const f=$({...n,[e]:s});c(f)}function xe(e){const t=e.trim();if(!t){c({start:null,end:null});return}const a=t.match(/\d{4}[^\d]\d{1,2}[^\d]\d{1,2}/g)??[],s=a[0],f=a[1];if(!s)return;const D=L(s),B=f?L(f):null;D&&r.isWithinRange(D,m,j)&&(B&&!r.isWithinRange(B,m,j)||c($({start:D,end:B})))}function _e(e){if(y&&!P){if(e.key==="Escape"){e.preventDefault(),ae();return}if(_==="days"){if(e.key==="ArrowLeft"){e.preventDefault(),h(t=>r.addDays(t,-1));return}if(e.key==="ArrowRight"){e.preventDefault(),h(t=>r.addDays(t,1));return}if(e.key==="ArrowUp"){e.preventDefault(),h(t=>r.addDays(t,-7));return}if(e.key==="ArrowDown"){e.preventDefault(),h(t=>r.addDays(t,7));return}if(e.key==="PageUp"){e.preventDefault(),T(-1);return}if(e.key==="PageDown"){e.preventDefault(),T(1);return}if(e.key==="Enter"){if(e.preventDefault(),!r.isWithinRange(k,m,j))return;ie(k)}}}}function T(e){const t=r.fromJalaliParts({jy:u.jy,jm:u.jm,jd:1}),a=r.addJalaliMonths(t,e),s=r.toJalaliParts(a);S({jy:s.jy,jm:s.jm}),h(f=>r.addJalaliMonths(f,e))}function De(e){const t=r.fromJalaliParts({jy:e,jm:1,jd:1}),a=r.fromJalaliParts({jy:e+1,jm:1,jd:1});return{start:t,endExclusive:a}}function be(e,t){const a=r.fromJalaliParts({jy:e,jm:t,jd:1}),s=t===12?{jy:e+1,jm:1}:{jy:e,jm:t+1},f=r.fromJalaliParts({jy:s.jy,jm:s.jm,jd:1});return{start:a,endExclusive:f}}function oe(e){return!(m&&r.compareDays(e.endExclusive,m)<=0||j&&r.compareDays(e.start,j)>0)}function Pe(){if(_==="days"){J("years");const e=u.jy;C(e),R(e-e%12)}else J("days")}function Je(e){C(e),J("months")}function Re(e){const t={jy:N,jm:e};S(t),h(()=>r.fromJalaliParts({jy:t.jy,jm:t.jm,jd:1})),J("days")}function ie(e){if(!r.isWithinRange(e,m,j))return;const t=n.start,a=n.end;if(!t||t&&a){c({start:e,end:null}),H("end");return}const s=$({start:t,end:e});c(s),g==="popover"&&ae()}const Se=n.end??K,ke=!!(n.start&&!n.end&&K);function Me(e){const t=l("dvx-pdp__day",p?.day,!e.inCurrentMonth&&l("dvx-pdp__day--outside",p?.dayOutside),re(e)&&l("dvx-pdp__day--disabled",p?.dayDisabled),r.isSameDay(e.gregorian,b())&&l("dvx-pdp__day--today",p?.dayToday)),a=n.start,s=a?Se:null;return a&&r.isSameDay(e.gregorian,a)?l(t,"dvx-pdp__day--rangeStart",p?.dayRangeStart):s&&n.end&&r.isSameDay(e.gregorian,n.end)?l(t,"dvx-pdp__day--rangeEnd",p?.dayRangeEnd):a&&s&&(n.end||ke)&&Te(e.gregorian,a,s)?l(t,"dvx-pdp__day--inRange",p?.dayInRange):t}const de=o.jsxs("div",{ref:q,tabIndex:-1,className:"dvx-pdp__calendar",onKeyDown:_e,children:[o.jsxs("div",{className:l("dvx-pdp__header",p?.header),children:[o.jsx("button",{type:"button",className:l("dvx-pdp__nav",p?.navButton),onClick:_==="days"?()=>T(-1):()=>R(e=>e-12),"aria-label":"Previous month",children:"‹"}),o.jsx("button",{type:"button",className:l("dvx-pdp__monthLabel",p?.monthLabel),onClick:Pe,"aria-label":"Choose month and year",children:_==="days"?ge:N}),o.jsx("button",{type:"button",className:l("dvx-pdp__nav",p?.navButton),onClick:_==="days"?()=>T(1):()=>R(e=>e+12),"aria-label":"Next month",children:"›"})]}),_==="days"?o.jsxs("div",{className:l("dvx-pdp__grid",p?.grid),children:[o.jsx("div",{className:"dvx-pdp__weekdays","aria-hidden":"true",children:ve.map((e,t)=>o.jsx("div",{className:l("dvx-pdp__weekday",p?.weekday),children:e},t))}),o.jsx("div",{className:"dvx-pdp__days",children:he.map((e,t)=>o.jsx("div",{className:"dvx-pdp__row",children:e.map(a=>{const s=re(a),f=r.isSameDay(a.gregorian,k);return o.jsx("button",{type:"button",className:l(Me(a),f&&"dvx-pdp__day--focused"),disabled:s,onClick:()=>ie(a.gregorian),onMouseEnter:()=>{a.inCurrentMonth&&(h(a.gregorian),n.start&&!n.end&&Q(a.gregorian))},onMouseLeave:()=>Q(null),children:a.jalali.jd},`${a.jalali.jy}-${a.jalali.jm}-${a.jalali.jd}`)})},t))})]}):_==="years"?o.jsx("div",{className:"dvx-pdp__panel",children:o.jsx("div",{className:"dvx-pdp__panelGrid",children:Array.from({length:12}).map((e,t)=>{const a=je+t,s=oe(De(a)),f=a===u.jy;return o.jsx("button",{type:"button",className:l("dvx-pdp__cell",f&&"dvx-pdp__cell--active"),disabled:!s,onClick:()=>Je(a),children:a},a)})})}):o.jsx("div",{className:"dvx-pdp__panel",children:o.jsx("div",{className:"dvx-pdp__panelGrid",children:Array.from({length:12}).map((e,t)=>{const a=t+1,s=oe(be(N,a)),f=N===u.jy&&a===u.jm,D=x&&x.length===12?x[a-1]??String(a):String(a);return o.jsx("button",{type:"button",className:l("dvx-pdp__cell",f&&"dvx-pdp__cell--active"),disabled:!s,onClick:()=>Re(a),children:D},a)})})})]});return o.jsxs("div",{ref:V,className:l("dvx-pdp",g==="inline"&&"dvx-pdp--inline",fe,p?.root),dir:"rtl",children:[g==="inline"?null:o.jsx("div",{className:"dvx-pdp__control",children:W==="single"?o.jsx("input",{ref:Y,className:l("dvx-pdp__input",p?.input),disabled:P,placeholder:le,inputMode:"numeric",autoComplete:"off",value:ne,onChange:e=>E(e.target.value),onClick:()=>F(z),onBlur:()=>xe(ne),"aria-haspopup":"dialog","aria-expanded":y}):o.jsxs(o.Fragment,{children:[o.jsx("input",{ref:U,className:l("dvx-pdp__input",p?.input),disabled:P,placeholder:ce,inputMode:"numeric",autoComplete:"off",value:X,onChange:e=>Z(e.target.value),onClick:()=>F("start"),onBlur:()=>se("start",X),"aria-haspopup":"dialog","aria-expanded":y}),o.jsx("input",{ref:I,className:l("dvx-pdp__input",p?.input),disabled:P,placeholder:ue,inputMode:"numeric",autoComplete:"off",value:ee,onChange:e=>te(e.target.value),onClick:()=>F("end"),onBlur:()=>se("end",ee),"aria-haspopup":"dialog","aria-expanded":y})]})}),g==="inline"?de:y?o.jsx("div",{className:l("dvx-pdp__popover",p?.popover),role:"dialog","aria-modal":"false",children:de}):null]})}exports.PersianDatePicker=r.PersianDatePicker;exports.addDays=r.addDays;exports.addJalaliMonths=r.addJalaliMonths;exports.buildJalaliMonthGrid=r.buildJalaliMonthGrid;exports.clampToRange=r.clampToRange;exports.compareDays=r.compareDays;exports.formatJalali=r.formatJalali;exports.fromJalaliParts=r.fromJalaliParts;exports.getJalaliMonthLength=r.getJalaliMonthLength;exports.isSameDay=r.isSameDay;exports.isWithinRange=r.isWithinRange;exports.parseJalaliText=r.parseJalaliText;exports.toGregorian=r.toGregorian;exports.toJalali=r.toJalali;exports.toJalaliParts=r.toJalaliParts;exports.PersianDateRangePicker=$e;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./PersianDatePicker-Bcz6VNVe.cjs"),i=require("react/jsx-runtime"),Be=require("react"),We=require("react-dom");function Ge(d){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(d){for(const c in d)if(c!=="default"){const m=Object.getOwnPropertyDescriptor(d,c);Object.defineProperty(n,c,m.get?m:{enumerable:!0,get:()=>d[c]})}}return n.default=d,Object.freeze(n)}const o=Ge(Be);function l(...d){return d.filter(Boolean).join(" ")}function Ve(d){return r.toJalali(d).formatted}function Ie(d){return r.parseJalaliText(d,{allowLooseSeparators:!0})}function b(){const d=new Date;return d.setHours(0,0,0,0),d}function A(d){const{start:n,end:c}=d;return n&&c&&r.compareDays(n,c)>0?{start:c,end:n}:d}function Ye(d,n,c){const m=r.compareDays(n,c)<=0?n:c,v=r.compareDays(n,c)<=0?c:n;return r.compareDays(d,m)>=0&&r.compareDays(d,v)<=0}function Ue(d){const{value:n,onChange:c,minDate:m,maxDate:v,disabled:P,inputVariant:F="two",placeholder:fe,rangeSeparator:S=" - ",placeholderStart:me,placeholderEnd:ye,open:B,onOpenChange:K,mode:j="popover",popover:je,formatValue:g=Ve,parseValue:W=Ie,weekdays:N,monthLabels:h,renderMonthLabel:G,prevIcon:ve,nextIcon:ge,className:xe,classes:u}=d,Q=o.useRef(null),C=o.useRef(null),V=o.useRef(null),I=o.useRef(null),Y=o.useRef(null),X=o.useRef(null),[he,_e]=o.useState(!1),[De,be]=o.useState(!1),y=j==="inline"?!0:B??De,E=o.useCallback(e=>{K?.(e),j!=="inline"&&B===void 0&&be(e)},[j,K,B]);o.useEffect(()=>{_e(!0)},[]);const[U,Z]=o.useState("start"),[_,R]=o.useState("days"),[Pe,k]=o.useState(()=>{const e=n.start??n.end??b(),t=r.toJalaliParts(e).jy;return t-t%12}),[T,$]=o.useState(()=>{const e=n.start??n.end??b();return r.toJalaliParts(e).jy}),[p,M]=o.useState(()=>{const e=n.start??n.end??b(),t=r.toJalaliParts(e);return{jy:t.jy,jm:t.jm}}),[w,x]=o.useState(()=>n.start??n.end??b()),[ee,te]=o.useState(null),[ne,ae]=o.useState(()=>n.start?g(n.start):""),[re,se]=o.useState(()=>n.end?g(n.end):""),[oe,L]=o.useState(()=>{const e=n.start?g(n.start):"",t=n.end?g(n.end):"";return!e&&!t?"":e&&!t?`${e}${S}`:`${e}${S}${t}`});o.useEffect(()=>{ae(n.start?g(n.start):""),se(n.end?g(n.end):"");const e=n.start?g(n.start):"",t=n.end?g(n.end):"";L(!e&&!t?"":e&&!t?`${e}${S}`:`${e}${S}${t}`);const a=n.start??n.end??b(),s=r.toJalaliParts(a);M({jy:s.jy,jm:s.jm}),x(a),$(s.jy),k(s.jy-s.jy%12)},[g,S,n.end,n.start]),o.useEffect(()=>{if(j!=="popover"||!y)return;const e=t=>{const a=Q.current;if(!a)return;const s=C.current;t.target instanceof Node&&!a.contains(t.target)&&!(s&&s.contains(t.target))&&E(!1)};return document.addEventListener("pointerdown",e),()=>document.removeEventListener("pointerdown",e)},[j,y,E]),o.useEffect(()=>{y&&X.current?.focus()},[y]);const J=je??{},ie=J.portal??!0,Re=F==="single"?V:U==="start"?I:Y,{style:Je}=r.usePopoverPosition(j==="popover"&&y&&ie,Re,C,{gutter:J.gutter,padding:J.padding,strategy:J.strategy,placements:J.placements,align:J.align??"end"});o.useEffect(()=>{if(!y)return;const e=r.toJalaliParts(w);M(t=>t.jy===e.jy&&t.jm===e.jm?t:{jy:e.jy,jm:e.jm})},[w,y]);const Se=o.useMemo(()=>G?G(p.jy,p.jm):h&&h.length===12?`${h[p.jm-1]??String(p.jm)} ${p.jy}`:`${p.jy} / ${p.jm}`,[h,G,p.jm,p.jy]),ke=o.useMemo(()=>N&&N.length===7?N:["1","2","3","4","5","6","7"],[N]),Me=o.useMemo(()=>r.buildJalaliMonthGrid({jy:p.jy,jm:p.jm}),[p.jm,p.jy]);function q(e){if(P)return;Z(e),E(!0);const t=(e==="start"?n.start:n.end)??n.start??n.end??b(),a=r.toJalaliParts(t);M({jy:a.jy,jm:a.jm}),x(t),R("days"),$(a.jy),k(a.jy-a.jy%12)}function de(){E(!1),R("days"),j==="popover"&&(F==="single"?V.current?.focus():(U==="start"?I:Y).current?.focus())}function le(e){return P?!0:!r.isWithinRange(e.gregorian,m,v)}function ce(e,t){const a=t.trim();if(!a){const D=A({...n,[e]:null});c(D);return}const s=W(a);if(!s||!r.isWithinRange(s,m,v))return;const f=A({...n,[e]:s});c(f)}function we(e){const t=e.trim();if(!t){c({start:null,end:null});return}const a=t.match(/\d{4}[^\d]\d{1,2}[^\d]\d{1,2}/g)??[],s=a[0],f=a[1];if(!s)return;const D=W(s),H=f?W(f):null;D&&r.isWithinRange(D,m,v)&&(H&&!r.isWithinRange(H,m,v)||c(A({start:D,end:H})))}function Ne(e){if(y&&!P){if(e.key==="Escape"){e.preventDefault(),de();return}if(_==="days"){if(e.key==="ArrowLeft"){e.preventDefault(),x(t=>r.addDays(t,-1));return}if(e.key==="ArrowRight"){e.preventDefault(),x(t=>r.addDays(t,1));return}if(e.key==="ArrowUp"){e.preventDefault(),x(t=>r.addDays(t,-7));return}if(e.key==="ArrowDown"){e.preventDefault(),x(t=>r.addDays(t,7));return}if(e.key==="PageUp"){e.preventDefault(),O(-1);return}if(e.key==="PageDown"){e.preventDefault(),O(1);return}if(e.key==="Enter"){if(e.preventDefault(),!r.isWithinRange(w,m,v))return;pe(w)}}}}function O(e){const t=r.fromJalaliParts({jy:p.jy,jm:p.jm,jd:1}),a=r.addJalaliMonths(t,e),s=r.toJalaliParts(a);M({jy:s.jy,jm:s.jm}),x(f=>r.addJalaliMonths(f,e))}function Ce(e){const t=r.fromJalaliParts({jy:e,jm:1,jd:1}),a=r.fromJalaliParts({jy:e+1,jm:1,jd:1});return{start:t,endExclusive:a}}function Ee(e,t){const a=r.fromJalaliParts({jy:e,jm:t,jd:1}),s=t===12?{jy:e+1,jm:1}:{jy:e,jm:t+1},f=r.fromJalaliParts({jy:s.jy,jm:s.jm,jd:1});return{start:a,endExclusive:f}}function ue(e){return!(m&&r.compareDays(e.endExclusive,m)<=0||v&&r.compareDays(e.start,v)>0)}function Te(){if(_==="days"){R("years");const e=p.jy;$(e),k(e-e%12)}else R("days")}function $e(e){$(e),R("months")}function Le(e){const t={jy:T,jm:e};M(t),x(()=>r.fromJalaliParts({jy:t.jy,jm:t.jm,jd:1})),R("days")}function pe(e){if(!r.isWithinRange(e,m,v))return;const t=n.start,a=n.end;if(!t||t&&a){c({start:e,end:null}),Z("end");return}const s=A({start:t,end:e});c(s),j==="popover"&&de()}const Oe=n.end??ee,Ae=!!(n.start&&!n.end&&ee);function Fe(e){const t=l("dvx-pdp__day",u?.day,!e.inCurrentMonth&&l("dvx-pdp__day--outside",u?.dayOutside),le(e)&&l("dvx-pdp__day--disabled",u?.dayDisabled),r.isSameDay(e.gregorian,b())&&l("dvx-pdp__day--today",u?.dayToday)),a=n.start,s=a?Oe:null;return a&&r.isSameDay(e.gregorian,a)?l(t,"dvx-pdp__day--rangeStart",u?.dayRangeStart):s&&n.end&&r.isSameDay(e.gregorian,n.end)?l(t,"dvx-pdp__day--rangeEnd",u?.dayRangeEnd):a&&s&&(n.end||Ae)&&Ye(e.gregorian,a,s)?l(t,"dvx-pdp__day--inRange",u?.dayInRange):t}const z=i.jsxs("div",{ref:X,tabIndex:-1,className:"dvx-pdp__calendar",onKeyDown:Ne,children:[i.jsxs("div",{className:l("dvx-pdp__header",u?.header),children:[i.jsx("button",{type:"button",className:l("dvx-pdp__nav",u?.navButton),onClick:_==="days"?()=>O(-1):()=>k(e=>e-12),"aria-label":"Previous month",children:ve??"‹"}),i.jsx("button",{type:"button",className:l("dvx-pdp__monthLabel",u?.monthLabel),onClick:Te,"aria-label":"Choose month and year",children:_==="days"?Se:T}),i.jsx("button",{type:"button",className:l("dvx-pdp__nav",u?.navButton),onClick:_==="days"?()=>O(1):()=>k(e=>e+12),"aria-label":"Next month",children:ge??"›"})]}),_==="days"?i.jsxs("div",{className:l("dvx-pdp__grid",u?.grid),children:[i.jsx("div",{className:"dvx-pdp__weekdays","aria-hidden":"true",children:ke.map((e,t)=>i.jsx("div",{className:l("dvx-pdp__weekday",u?.weekday),children:e},t))}),i.jsx("div",{className:"dvx-pdp__days",children:Me.map((e,t)=>i.jsx("div",{className:"dvx-pdp__row",children:e.map(a=>{const s=le(a),f=r.isSameDay(a.gregorian,w);return i.jsx("button",{type:"button",className:l(Fe(a),f&&"dvx-pdp__day--focused"),disabled:s,onClick:()=>pe(a.gregorian),onMouseEnter:()=>{a.inCurrentMonth&&(x(a.gregorian),n.start&&!n.end&&te(a.gregorian))},onMouseLeave:()=>te(null),children:a.jalali.jd},`${a.jalali.jy}-${a.jalali.jm}-${a.jalali.jd}`)})},t))})]}):_==="years"?i.jsx("div",{className:"dvx-pdp__panel",children:i.jsx("div",{className:"dvx-pdp__panelGrid",children:Array.from({length:12}).map((e,t)=>{const a=Pe+t,s=ue(Ce(a)),f=a===p.jy;return i.jsx("button",{type:"button",className:l("dvx-pdp__cell",f&&"dvx-pdp__cell--active"),disabled:!s,onClick:()=>$e(a),children:a},a)})})}):i.jsx("div",{className:"dvx-pdp__panel",children:i.jsx("div",{className:"dvx-pdp__panelGrid",children:Array.from({length:12}).map((e,t)=>{const a=t+1,s=ue(Ee(T,a)),f=T===p.jy&&a===p.jm,D=h&&h.length===12?h[a-1]??String(a):String(a);return i.jsx("button",{type:"button",className:l("dvx-pdp__cell",f&&"dvx-pdp__cell--active"),disabled:!s,onClick:()=>Le(a),children:D},a)})})})]});return i.jsxs("div",{ref:Q,className:l("dvx-pdp",j==="inline"&&"dvx-pdp--inline",xe,u?.root),dir:"rtl",children:[j==="inline"?null:i.jsx("div",{className:"dvx-pdp__control",children:F==="single"?i.jsx("input",{ref:V,className:l("dvx-pdp__input",u?.input),disabled:P,placeholder:fe,inputMode:"numeric",autoComplete:"off",value:oe,onChange:e=>L(e.target.value),onClick:()=>q(U),onBlur:()=>we(oe),"aria-haspopup":"dialog","aria-expanded":y}):i.jsxs(i.Fragment,{children:[i.jsx("input",{ref:I,className:l("dvx-pdp__input",u?.input),disabled:P,placeholder:me,inputMode:"numeric",autoComplete:"off",value:ne,onChange:e=>ae(e.target.value),onClick:()=>q("start"),onBlur:()=>ce("start",ne),"aria-haspopup":"dialog","aria-expanded":y}),i.jsx("input",{ref:Y,className:l("dvx-pdp__input",u?.input),disabled:P,placeholder:ye,inputMode:"numeric",autoComplete:"off",value:re,onChange:e=>se(e.target.value),onClick:()=>q("end"),onBlur:()=>ce("end",re),"aria-haspopup":"dialog","aria-expanded":y})]})}),j==="inline"?z:y?ie&&he?We.createPortal(i.jsx("div",{ref:C,className:l("dvx-pdp__popover","dvx-pdp__popover--portal",u?.popover),dir:"rtl",style:{...Je,right:"auto",bottom:"auto"},role:"dialog","aria-modal":"false",children:z}),document.body):i.jsx("div",{ref:C,className:l("dvx-pdp__popover",u?.popover),role:"dialog","aria-modal":"false",children:z}):null]})}exports.PersianDatePicker=r.PersianDatePicker;exports.addDays=r.addDays;exports.addJalaliMonths=r.addJalaliMonths;exports.buildJalaliMonthGrid=r.buildJalaliMonthGrid;exports.clampToRange=r.clampToRange;exports.compareDays=r.compareDays;exports.formatJalali=r.formatJalali;exports.fromJalaliParts=r.fromJalaliParts;exports.getJalaliMonthLength=r.getJalaliMonthLength;exports.isSameDay=r.isSameDay;exports.isWithinRange=r.isWithinRange;exports.parseJalaliText=r.parseJalaliText;exports.toGregorian=r.toGregorian;exports.toJalali=r.toJalali;exports.toJalaliParts=r.toJalaliParts;exports.PersianDateRangePicker=Ue;
|
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export { PersianDatePicker } from './components/PersianDatePicker';
|
|
|
2
2
|
export type { PersianDatePickerProps, PersianDatePickerClasses } from './components/PersianDatePicker';
|
|
3
3
|
export { PersianDateRangePicker } from './components/PersianDateRangePicker';
|
|
4
4
|
export type { PersianDateRangePickerProps, PersianDateRangePickerClasses, PersianDateRange } from './components/PersianDateRangePicker';
|
|
5
|
+
export type { PopoverConfig, BasePickerProps, BasePickerClasses } from './types/shared';
|
|
5
6
|
export type { JalaliParts, FormatJalaliOptions } from './adapters/dayjsAdapter';
|
|
6
7
|
export { toJalaliParts, fromJalaliParts, formatJalali } from './adapters/dayjsAdapter';
|
|
7
8
|
export { toJalali } from './utils/toJalali';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAA;AAClE,YAAY,EAAE,sBAAsB,EAAE,wBAAwB,EAAE,MAAM,gCAAgC,CAAA;AAEtG,OAAO,EAAE,sBAAsB,EAAE,MAAM,qCAAqC,CAAA;AAC5E,YAAY,EAAE,2BAA2B,EAAE,6BAA6B,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAA;AAEvI,YAAY,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAA;AAC/E,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAA;AAEtF,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAC3C,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAElE,OAAO,EACL,OAAO,EACP,eAAe,EACf,oBAAoB,EACpB,YAAY,EACZ,WAAW,EACX,oBAAoB,EACpB,SAAS,EACT,aAAa,GACd,MAAM,sBAAsB,CAAA;AAC7B,YAAY,EAAE,eAAe,EAAE,2BAA2B,EAAE,MAAM,sBAAsB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAA;AAClE,YAAY,EAAE,sBAAsB,EAAE,wBAAwB,EAAE,MAAM,gCAAgC,CAAA;AAEtG,OAAO,EAAE,sBAAsB,EAAE,MAAM,qCAAqC,CAAA;AAC5E,YAAY,EAAE,2BAA2B,EAAE,6BAA6B,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAA;AAEvI,YAAY,EAAE,aAAa,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AAEvF,YAAY,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAA;AAC/E,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAA;AAEtF,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAC3C,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAElE,OAAO,EACL,OAAO,EACP,eAAe,EACf,oBAAoB,EACpB,YAAY,EACZ,WAAW,EACX,oBAAoB,EACpB,SAAS,EACT,aAAa,GACd,MAAM,sBAAsB,CAAA;AAC7B,YAAY,EAAE,eAAe,EAAE,2BAA2B,EAAE,MAAM,sBAAsB,CAAA"}
|