@kashi-ui/react 2.24.0 → 2.25.0

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/README.md CHANGED
@@ -20,7 +20,7 @@ export function SignUp() {
20
20
  }
21
21
  ```
22
22
 
23
- کامپوننت‌ها: Button · Input · Textarea · Select · Checkbox · RadioGroup · Switch · Badge · Card · Alert · Avatar · AvatarGroup · Tabs · Dialog · Toast · Tooltip · DropdownMenu · DataTable · Pagination · Breadcrumb · Accordion · Stepper · Progress · Spinner · Skeleton · EmptyState · Divider · Kbd · RelativeTime · Combobox · MultiSelect · CommandPalette · TagInput · FileUpload · Slider · NumberInput · Popover · StatCard · Timeline · SideNav · SegmentedControl · CopyButton · Banner · Rating · TreeView · ButtonGroup · ChipGroup · PasswordStrength · BarChart · LineChart · ContextMenu · InlineEdit · PieChart · BarList · ProportionBar · Sparkline · Carousel · ColorPicker · Tour · Meter · Splitter · ChatThread · ChatMessage · TypingIndicator · ChatComposer · StreamingText · CodeBlock · SortableList · Kanban · Gallery · Lightbox · RichTextEditor · NotificationCenter · QRCode · Scheduler
23
+ کامپوننت‌ها: Button · Input · Textarea · Select · Checkbox · RadioGroup · Switch · Badge · Card · Alert · Avatar · AvatarGroup · Tabs · Dialog · Toast · Tooltip · DropdownMenu · DataTable · Pagination · Breadcrumb · Accordion · Stepper · Progress · Spinner · Skeleton · EmptyState · Divider · Kbd · RelativeTime · Combobox · MultiSelect · CommandPalette · TagInput · FileUpload · Slider · NumberInput · Popover · StatCard · Timeline · SideNav · SegmentedControl · CopyButton · Banner · Rating · TreeView · ButtonGroup · ChipGroup · PasswordStrength · BarChart · LineChart · ContextMenu · InlineEdit · PieChart · BarList · ProportionBar · Sparkline · Carousel · ColorPicker · Tour · Meter · Splitter · ChatThread · ChatMessage · TypingIndicator · ChatComposer · StreamingText · CodeBlock · SortableList · Kanban · Gallery · Lightbox · RichTextEditor · NotificationCenter · QRCode · Scheduler · Gantt · SignaturePad · ImageCropper · Invoice · VirtualList · InfiniteScroll · BillIdInput · PaymentIdInput
24
24
 
25
25
  فارسی: DatePicker و Calendar شمسی · DateRangePicker · TimeInput · TimePicker · TimeClock · PostalCodeInput · PlateInput · LandlineInput · MonthPicker · Countdown · ActivityHeatmap · ProvinceSelect · NationalIdInput · CardNumberInput · IbanInput · MobileInput · PriceInput · OtpInput
26
26
 
@@ -0,0 +1,39 @@
1
+ import { type ReactNode } from "react";
2
+ import { type BillInfo, type BillService } from "@kashi-ui/persian";
3
+ import { type InputProps } from "./Input.js";
4
+ type Base = Omit<InputProps, "value" | "defaultValue" | "onChange" | "type" | "inputMode">;
5
+ export interface BillIdInputProps extends Base {
6
+ /** ارقام لاتین، مثل "7748317800142" */
7
+ value?: string;
8
+ defaultValue?: string;
9
+ onValueChange?: (value: string, valid: boolean, service: BillService | null) => void;
10
+ /** نوع قبض (آب، برق، گاز…) کنار فیلد @default true */
11
+ showService?: boolean;
12
+ /** @default "fa" */
13
+ digits?: "fa" | "latin";
14
+ invalidMessage?: ReactNode;
15
+ }
16
+ /**
17
+ * شناسهٔ قبض (۶ تا ۱۳ رقم): رقم کنترل استاندارد بانک مرکزی بررسی می‌شود و نوع قبض
18
+ * (آب، برق، گاز، تلفن، شهرداری، مالیات، جریمه) از رقم یکی‌مانده‌به‌آخر کنار فیلد می‌آید.
19
+ */
20
+ export declare const BillIdInput: import("react").ForwardRefExoticComponent<BillIdInputProps & import("react").RefAttributes<HTMLInputElement>>;
21
+ export interface PaymentIdInputProps extends Base {
22
+ /** شناسهٔ قبضی که این شناسهٔ پرداخت مال آن است؛ رقم کنترل دوم به آن بسته است */
23
+ billId: string;
24
+ value?: string;
25
+ defaultValue?: string;
26
+ onValueChange?: (value: string, valid: boolean, info: BillInfo | null) => void;
27
+ /** مبلغ قبض کنار فیلد @default true */
28
+ showAmount?: boolean;
29
+ /** واحد نمایش مبلغ @default "toman" */
30
+ unit?: "rial" | "toman";
31
+ /** @default "fa" */
32
+ digits?: "fa" | "latin";
33
+ invalidMessage?: ReactNode;
34
+ }
35
+ /**
36
+ * شناسهٔ پرداخت قبض: هر دو رقم کنترل بررسی می‌شوند (دومی همراه شناسهٔ قبض) و مبلغ قبض کنار فیلد می‌آید.
37
+ */
38
+ export declare const PaymentIdInput: import("react").ForwardRefExoticComponent<PaymentIdInputProps & import("react").RefAttributes<HTMLInputElement>>;
39
+ export {};
@@ -0,0 +1,54 @@
1
+ "use client";
2
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { forwardRef, useId, useState } from "react";
4
+ import { billService, formatMoney, isValidBillId, parseBill } from "@kashi-ui/persian";
5
+ import { Input } from "./Input.js";
6
+ import { useDigitsInput } from "./useDigitsInput.js";
7
+ import { mergeRefs } from "./utils.js";
8
+ import { useKashi } from "./KashiProvider.js";
9
+ /**
10
+ * شناسهٔ قبض (۶ تا ۱۳ رقم): رقم کنترل استاندارد بانک مرکزی بررسی می‌شود و نوع قبض
11
+ * (آب، برق، گاز، تلفن، شهرداری، مالیات، جریمه) از رقم یکی‌مانده‌به‌آخر کنار فیلد می‌آید.
12
+ */
13
+ export const BillIdInput = forwardRef(function BillIdInput({ value, defaultValue, onValueChange, showService = true, digits, invalidMessage, error, name, onBlur, placeholder, ...rest }, ref) {
14
+ const { messages: M, digits: D } = useKashi();
15
+ digits ?? (digits = D);
16
+ invalidMessage ?? (invalidMessage = M.invalid.billId);
17
+ const { raw, shown, inputRef, handleChange } = useDigitsInput({ value, defaultValue, maxDigits: 13, format: (d) => d, digits });
18
+ const [touched, setTouched] = useState(false);
19
+ const valid = isValidBillId(raw);
20
+ const service = valid ? billService(raw) : null;
21
+ const metaId = useId();
22
+ const showInvalid = raw.length > 0 && (touched || raw.length === 13) && !valid;
23
+ return (_jsxs(_Fragment, { children: [_jsx(Input, { ref: mergeRefs(ref, inputRef), type: "text", inputMode: "numeric", autoComplete: "off", dir: "ltr", placeholder: placeholder ?? (digits === "fa" ? "۰۰۰۰۰۰۰۰۰۰۰۰۰" : "0000000000000"), value: shown, onChange: (e) => {
24
+ const next = handleChange(e);
25
+ const ok = isValidBillId(next);
26
+ onValueChange?.(next, ok, ok ? billService(next) : null);
27
+ }, onBlur: (e) => {
28
+ setTouched(true);
29
+ onBlur?.(e);
30
+ }, addonEnd: showService && service ? _jsx("span", { className: "k-input__meta k-bill__service", "data-service": service, id: metaId, children: M.bill.service[service] }) : undefined, "aria-describedby": showService && service ? metaId : undefined, error: error ?? (showInvalid ? invalidMessage : undefined), ...rest }), name && _jsx("input", { type: "hidden", name: name, value: raw })] }));
31
+ });
32
+ /**
33
+ * شناسهٔ پرداخت قبض: هر دو رقم کنترل بررسی می‌شوند (دومی همراه شناسهٔ قبض) و مبلغ قبض کنار فیلد می‌آید.
34
+ */
35
+ export const PaymentIdInput = forwardRef(function PaymentIdInput({ billId, value, defaultValue, onValueChange, showAmount = true, unit = "toman", digits, invalidMessage, error, hint, name, onBlur, placeholder, ...rest }, ref) {
36
+ const { messages: M, digits: D, locale } = useKashi();
37
+ digits ?? (digits = D);
38
+ invalidMessage ?? (invalidMessage = M.invalid.paymentId);
39
+ const { raw, shown, inputRef, handleChange } = useDigitsInput({ value, defaultValue, maxDigits: 13, format: (d) => d, digits });
40
+ const [touched, setTouched] = useState(false);
41
+ const billOk = isValidBillId(billId);
42
+ const info = parseBill(billId, raw);
43
+ const metaId = useId();
44
+ const showInvalid = billOk && raw.length > 0 && (touched || raw.length === 13) && !info;
45
+ const amount = info ? formatMoney(info.amount, { from: "rial", unit, locale, digits }) : "";
46
+ return (_jsxs(_Fragment, { children: [_jsx(Input, { ref: mergeRefs(ref, inputRef), type: "text", inputMode: "numeric", autoComplete: "off", dir: "ltr", placeholder: placeholder ?? (digits === "fa" ? "۰۰۰۰۰۰۰۰" : "00000000"), value: shown, onChange: (e) => {
47
+ const next = handleChange(e);
48
+ const parsed = parseBill(billId, next);
49
+ onValueChange?.(next, !!parsed, parsed);
50
+ }, onBlur: (e) => {
51
+ setTouched(true);
52
+ onBlur?.(e);
53
+ }, addonEnd: showAmount && info ? _jsx("span", { className: "k-input__meta k-bill__amount", id: metaId, children: amount }) : undefined, "aria-describedby": showAmount && info ? metaId : undefined, hint: hint ?? (!billOk ? M.bill.needBill : undefined), error: error ?? (showInvalid ? invalidMessage : undefined), ...rest }), name && _jsx("input", { type: "hidden", name: name, value: raw })] }));
54
+ });
@@ -12,6 +12,10 @@ export interface ComboboxOption {
12
12
  }
13
13
  /** متن یکدست برای جستجو: ي/ی، ك/ک، ارقام، حروف کوچک */
14
14
  export declare const searchText: (s: string) => string;
15
+ /**
16
+ * فیلتر پیش‌فرض با جستجوی فارسی کاشی (persianMatch): ي/ی و ك/ک یکی‌اند، نیم‌فاصله نادیده گرفته می‌شود،
17
+ * «mamad» «ممد» را پیدا می‌کند و متنی که با چیدمان انگلیسی صفحه‌کلید تایپ شده («hdvhk») هم «ایران» را.
18
+ */
15
19
  export declare function defaultFilter(option: ComboboxOption, query: string): boolean;
16
20
  /** بخش منطبق با جستجو را با <mark> برجسته می‌کند */
17
21
  export declare function highlight(text: string, query: string): ReactNode;
package/dist/Combobox.js CHANGED
@@ -1,18 +1,21 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { forwardRef, useEffect, useId, useMemo, useRef, useState } from "react";
4
- import { normalizePersian } from "@kashi-ui/persian";
4
+ import { normalizePersian, persianMatch } from "@kashi-ui/persian";
5
5
  import { cx } from "./cx.js";
6
6
  import { Field, describedBy } from "./Field.js";
7
7
  import { mergeRefs } from "./utils.js";
8
8
  import { useKashi } from "./KashiProvider.js";
9
9
  /** متن یکدست برای جستجو: ي/ی، ك/ک، ارقام، حروف کوچک */
10
10
  export const searchText = (s) => normalizePersian(s, { digits: "latin" }).toLowerCase();
11
+ /**
12
+ * فیلتر پیش‌فرض با جستجوی فارسی کاشی (persianMatch): ي/ی و ك/ک یکی‌اند، نیم‌فاصله نادیده گرفته می‌شود،
13
+ * «mamad» «ممد» را پیدا می‌کند و متنی که با چیدمان انگلیسی صفحه‌کلید تایپ شده («hdvhk») هم «ایران» را.
14
+ */
11
15
  export function defaultFilter(option, query) {
12
- const q = searchText(query.trim());
13
- if (!q)
16
+ if (!query.trim())
14
17
  return true;
15
- return [option.label, option.description ?? "", ...(option.keywords ?? [])].some((t) => searchText(t).includes(q));
18
+ return [option.label, option.description ?? "", ...(option.keywords ?? [])].some((t) => persianMatch(query, t) > 0);
16
19
  }
17
20
  /** بخش منطبق با جستجو را با <mark> برجسته می‌کند */
18
21
  export function highlight(text, query) {
@@ -1,4 +1,5 @@
1
1
  import { type ReactNode } from "react";
2
+ import type { XlsxCell } from "@kashi-ui/persian";
2
3
  export interface Column<T> {
3
4
  key: string;
4
5
  header: ReactNode;
@@ -16,6 +17,16 @@ export interface Column<T> {
16
17
  hideBelow?: "sm" | "md";
17
18
  /** کلاس خانه‌های این ستون */
18
19
  className?: string;
20
+ /** ستون ثابت هنگام اسکرول افقی: «start» (کنار شروع جدول) یا «end» */
21
+ pin?: "start" | "end";
22
+ /** ویرایش داخل خانه (با onCellEdit در جدول)؛ تابع برای ردیف‌به‌ردیف */
23
+ editable?: boolean | ((row: T) => boolean);
24
+ /** نوع ویرایشگر @default "text" (برای ستون numeric «number») */
25
+ editType?: "text" | "number";
26
+ /** مقدار این ستون در خروجی اکسل؛ پیش‌فرض row[key] (تاریخ شمسی می‌شود) */
27
+ exportValue?: (row: T) => XlsxCell;
28
+ /** سرستون در اکسل وقتی header متن ساده نیست */
29
+ exportHeader?: string;
19
30
  }
20
31
  export type SortState = {
21
32
  key: string;
@@ -59,6 +70,13 @@ export interface DataTableProps<T> {
59
70
  rowHeight?: number;
60
71
  overscan?: number;
61
72
  };
73
+ /** ویرایش یک خانه ثبت شد (Enter یا خروج از خانه) */
74
+ onCellEdit?: (row: T, key: string, value: string | number) => void;
75
+ /** دکمهٔ «خروجی اکسل» کنار عنوان: xlsx راست‌به‌چپ با تاریخ شمسی، به ترتیب مرتب‌سازی فعلی */
76
+ exportable?: boolean | {
77
+ fileName?: string;
78
+ sheetName?: string;
79
+ };
62
80
  labels?: {
63
81
  selectAll?: string;
64
82
  selectRow?: (row: T) => string;
@@ -75,4 +93,4 @@ export interface DataTableProps<T> {
75
93
  className?: string;
76
94
  }
77
95
  /** جدول داده با مرتب‌سازی (aria-sort)، انتخاب ردیف‌ها و حالت خالی */
78
- export declare function DataTable<T extends Record<string, unknown>>({ columns, rows, getRowId, caption, description, hideCaption, selectable, selected, onSelectedChange, sort, defaultSort, onSortChange, empty, compact, striped, stickyHeader, maxHeight, loading, onRowClick, footer, virtual, labels, classNames, className, }: DataTableProps<T>): import("react").JSX.Element;
96
+ export declare function DataTable<T extends Record<string, unknown>>({ columns, rows, getRowId, caption, description, hideCaption, selectable, selected, onSelectedChange, sort, defaultSort, onSortChange, empty, compact, striped, stickyHeader, maxHeight, loading, onRowClick, footer, virtual, onCellEdit, exportable, labels, classNames, className, }: DataTableProps<T>): import("react").JSX.Element;
package/dist/DataTable.js CHANGED
@@ -1,10 +1,11 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
- import { useEffect, useId, useLayoutEffect, useMemo, useRef, useState } from "react";
3
+ import { useCallback, useEffect, useId, useLayoutEffect, useMemo, useRef, useState } from "react";
4
+ import { toEnDigits } from "@kashi-ui/persian";
4
5
  import { cx } from "./cx.js";
5
6
  import { useKashi } from "./KashiProvider.js";
6
7
  /** جدول داده با مرتب‌سازی (aria-sort)، انتخاب ردیف‌ها و حالت خالی */
7
- export function DataTable({ columns, rows, getRowId, caption, description, hideCaption, selectable, selected, onSelectedChange, sort, defaultSort = null, onSortChange, empty, compact, striped, stickyHeader, maxHeight, loading, onRowClick, footer, virtual, labels = {}, classNames = {}, className, }) {
8
+ export function DataTable({ columns, rows, getRowId, caption, description, hideCaption, selectable, selected, onSelectedChange, sort, defaultSort = null, onSortChange, empty, compact, striped, stickyHeader, maxHeight, loading, onRowClick, footer, virtual, onCellEdit, exportable, labels = {}, classNames = {}, className, }) {
8
9
  const id = useId();
9
10
  const [innerSort, setInnerSort] = useState(defaultSort);
10
11
  const [innerSel, setInnerSel] = useState([]);
@@ -46,6 +47,76 @@ export function DataTable({ columns, rows, getRowId, caption, description, hideC
46
47
  const loadingRows = loading === true ? 5 : typeof loading === "number" ? loading : 0;
47
48
  const cellCls = (c) => cx(c.numeric && "k-table__num", c.align && !c.numeric && `k-table__align-${c.align}`, c.hideBelow && `k-table__hide-${c.hideBelow}`, c.className, classNames.cell) || undefined;
48
49
  const colCount = columns.length + (selectable ? 1 : 0);
50
+ // ---- ستون‌های ثابت: جای هر ستون از پهنای واقعی ستون‌های پیش از آن
51
+ const heads = useRef(new Map());
52
+ const checkHead = useRef(null);
53
+ const hasPin = columns.some((c) => c.pin);
54
+ const pinStart = columns.some((c) => c.pin === "start");
55
+ const [pinOff, setPinOff] = useState({});
56
+ const measurePins = useCallback(() => {
57
+ if (!hasPin)
58
+ return;
59
+ const next = {};
60
+ let acc = selectable && pinStart ? (checkHead.current?.offsetWidth ?? 0) : 0;
61
+ for (const c of columns)
62
+ if (c.pin === "start") {
63
+ next[c.key] = acc;
64
+ acc += heads.current.get(c.key)?.offsetWidth ?? 0;
65
+ }
66
+ acc = 0;
67
+ for (const c of [...columns].reverse())
68
+ if (c.pin === "end") {
69
+ next[c.key] = acc;
70
+ acc += heads.current.get(c.key)?.offsetWidth ?? 0;
71
+ }
72
+ setPinOff((old) => (Object.keys(next).every((k) => old[k] === next[k]) && Object.keys(old).length === Object.keys(next).length ? old : next));
73
+ }, [hasPin, pinStart, selectable, columns]);
74
+ const lastStart = [...columns].reverse().find((c) => c.pin === "start")?.key;
75
+ const firstEnd = columns.find((c) => c.pin === "end")?.key;
76
+ const pinStyle = (c) => (c.pin ? { [c.pin === "start" ? "insetInlineStart" : "insetInlineEnd"]: pinOff[c.key] ?? 0 } : undefined);
77
+ const pinCls = (c) => c.pin && cx("k-table__pin", (c.key === lastStart || c.key === firstEnd) && `k-table__pin--edge-${c.pin}`);
78
+ // ---- ویرایش داخل خانه
79
+ const [editing, setEditing] = useState(null);
80
+ const [draft, setDraft] = useState("");
81
+ const [live, setLive] = useState("");
82
+ const refocus = useRef(null);
83
+ const cellRefs = useRef(new Map());
84
+ const canEdit = (c, r) => !!onCellEdit && (typeof c.editable === "function" ? c.editable(r) : !!c.editable);
85
+ const startEdit = (rid, c, r) => {
86
+ const v = c.sortValue ? c.sortValue(r) : r[c.key];
87
+ setDraft(v == null ? "" : String(v));
88
+ setEditing({ row: rid, key: c.key });
89
+ };
90
+ const finishEdit = (r, c, save) => {
91
+ if (!editing)
92
+ return;
93
+ refocus.current = `${editing.row}:${editing.key}`;
94
+ setEditing(null);
95
+ if (!save)
96
+ return;
97
+ const type = c.editType ?? (c.numeric ? "number" : "text");
98
+ const raw = type === "number" ? toEnDigits(draft).replace(/[٬,\s]/g, "") : draft;
99
+ const value = type === "number" && raw !== "" && Number.isFinite(Number(raw)) ? Number(raw) : raw;
100
+ onCellEdit?.(r, c.key, value);
101
+ setLive(M.table.saved);
102
+ };
103
+ useEffect(() => {
104
+ if (!editing && refocus.current) {
105
+ cellRefs.current.get(refocus.current)?.focus();
106
+ refocus.current = null;
107
+ }
108
+ }, [editing]);
109
+ const hintId = `${id}-edit-hint`;
110
+ const exportExcel = async () => {
111
+ const { downloadXlsx } = await import("./xlsx.js");
112
+ const opts = typeof exportable === "object" ? exportable : {};
113
+ const header = columns.map((c) => c.exportHeader ?? (typeof c.header === "string" || typeof c.header === "number" ? String(c.header) : c.key));
114
+ const data = sorted.map((r) => columns.map((c) => {
115
+ const v = c.exportValue ? c.exportValue(r) : r[c.key];
116
+ return v == null || typeof v === "string" || typeof v === "number" || typeof v === "boolean" || v instanceof Date ? v : String(v);
117
+ }));
118
+ downloadXlsx(opts.fileName ?? "kashi-table", header, data, { sheetName: opts.sheetName });
119
+ };
49
120
  // ---- اسکرول مجازی
50
121
  const vOpts = virtual ? (typeof virtual === "object" ? virtual : {}) : null;
51
122
  const wrap = useRef(null);
@@ -70,6 +141,15 @@ export function DataTable({ columns, rows, getRowId, caption, description, hideC
70
141
  return () => { w.removeEventListener("scroll", on); ro?.disconnect(); cancelAnimationFrame(frame); };
71
142
  }, [!!vOpts]);
72
143
  const useIso = typeof window === "undefined" ? useEffect : useLayoutEffect;
144
+ useIso(() => { measurePins(); });
145
+ useEffect(() => {
146
+ const t = wrap.current?.querySelector("table");
147
+ if (!hasPin || !t || typeof ResizeObserver === "undefined")
148
+ return;
149
+ const ro = new ResizeObserver(() => measurePins());
150
+ ro.observe(t);
151
+ return () => ro.disconnect();
152
+ }, [hasPin, measurePins]);
73
153
  useIso(() => {
74
154
  // ارتفاع واقعی ردیف را از اولین ردیف ساخته‌شده بخوان
75
155
  if (!vOpts || vOpts.rowHeight)
@@ -88,18 +168,41 @@ export function DataTable({ columns, rows, getRowId, caption, description, hideC
88
168
  : null;
89
169
  const visible = win ? sorted.slice(win.first, win.last) : sorted;
90
170
  const spacer = (h, key) => h > 0 && _jsx("tr", { className: "k-table__spacer", "aria-hidden": "true", children: _jsx("td", { colSpan: colCount, style: { blockSize: h, padding: 0, border: 0 } }) }, key);
91
- return (_jsxs("div", { ref: wrap, className: cx("k-table-wrap", (stickyHeader || vOpts) && "k-table-wrap--sticky", vOpts && "k-table-wrap--virtual", className, classNames.root), role: "region", "aria-labelledby": `${id}-caption`, "aria-busy": loadingRows > 0 || undefined, tabIndex: 0, style: maxHeight || vOpts ? { maxBlockSize: maxHeight ?? "28rem" } : undefined, children: [_jsxs("table", { className: cx("k-table", compact && "k-table--compact", striped && "k-table--striped", onRowClick && "k-table--clickable", classNames.table), "aria-rowcount": vOpts ? sorted.length + 1 : undefined, children: [_jsxs("caption", { id: `${id}-caption`, className: hideCaption ? "k-sr-only" : undefined, children: [_jsx("span", { className: "k-table__caption-title", children: caption }), description && _jsx("span", { className: "k-table__caption-desc", children: description })] }), _jsx("thead", { children: _jsxs("tr", { "aria-rowindex": vOpts ? 1 : undefined, children: [selectable && (_jsx("th", { scope: "col", className: "k-table__check", children: _jsx("input", { ref: allRef, type: "checkbox", className: "k-checkbox", "aria-label": selectAll, checked: all, onChange: () => setSel(all ? [] : ids) }) })), columns.map((c) => {
171
+ return (_jsxs("div", { ref: wrap, className: cx("k-table-wrap", (stickyHeader || vOpts) && "k-table-wrap--sticky", vOpts && "k-table-wrap--virtual", className, classNames.root), role: "region", "aria-labelledby": `${id}-caption`, "aria-busy": loadingRows > 0 || undefined, tabIndex: 0, style: maxHeight || vOpts ? { maxBlockSize: maxHeight ?? "28rem" } : undefined, children: [_jsxs("table", { className: cx("k-table", hasPin && "k-table--pinned", compact && "k-table--compact", striped && "k-table--striped", onRowClick && "k-table--clickable", classNames.table), "aria-rowcount": vOpts ? sorted.length + 1 : undefined, children: [_jsxs("caption", { id: `${id}-caption`, className: hideCaption ? "k-sr-only" : undefined, children: [_jsx("span", { className: "k-table__caption-title", children: caption }), exportable && (_jsxs("button", { type: "button", className: "k-btn k-btn--secondary k-btn--sm k-table__export", onClick: exportExcel, children: [_jsx("svg", { viewBox: "0 0 20 20", width: "16", height: "16", "aria-hidden": "true", children: _jsx("path", { d: "M10 3v9m0 0-3.5-3.5M10 12l3.5-3.5M4 13.5V16h12v-2.5", fill: "none", stroke: "currentColor", strokeWidth: "1.6", strokeLinecap: "round", strokeLinejoin: "round" }) }), M.table.exportExcel] })), description && _jsx("span", { className: "k-table__caption-desc", children: description })] }), _jsx("thead", { children: _jsxs("tr", { "aria-rowindex": vOpts ? 1 : undefined, children: [selectable && (_jsx("th", { scope: "col", ref: checkHead, className: cx("k-table__check", pinStart && "k-table__pin"), style: pinStart ? { insetInlineStart: 0 } : undefined, children: _jsx("input", { ref: allRef, type: "checkbox", className: "k-checkbox", "aria-label": selectAll, checked: all, onChange: () => setSel(all ? [] : ids) }) })), columns.map((c) => {
92
172
  const s = activeSort?.key === c.key ? activeSort.direction : undefined;
93
- return (_jsx("th", { scope: "col", "aria-sort": c.sortable ? (s ?? "none") : undefined, className: cx(cellCls(c), classNames.header) || undefined, style: c.width ? { inlineSize: c.width } : undefined, children: c.sortable ? _jsx("button", { type: "button", className: "k-table__sort", onClick: () => setSort(c.key), children: c.header }) : c.header }, c.key));
94
- })] }) }), _jsx("tbody", { children: loadingRows > 0 ? (Array.from({ length: loadingRows }, (_, i) => (_jsxs("tr", { "aria-hidden": "true", children: [selectable && _jsx("td", { className: "k-table__check", children: _jsx("span", { className: "k-skeleton", style: { inlineSize: "1.125rem", blockSize: "1.125rem" } }) }), columns.map((c) => (_jsx("td", { className: cellCls(c), children: _jsx("span", { className: "k-skeleton", style: { inlineSize: `${50 + ((i * 17 + c.key.length * 11) % 40)}%` } }) }, c.key)))] }, `sk-${i}`)))) : sorted.length === 0 ? (_jsx("tr", { className: "k-table__empty", children: _jsx("td", { colSpan: colCount, children: empty ?? _jsx("p", { style: { padding: "2rem", margin: 0, textAlign: "center" }, children: M.table.empty }) }) })) : (_jsxs(_Fragment, { children: [win && spacer(win.before, "sp-top"), visible.map((r, vi) => {
173
+ return (_jsx("th", { ref: (el) => { heads.current.set(c.key, el); }, scope: "col", "aria-sort": c.sortable ? (s ?? "none") : undefined, className: cx(cellCls(c), pinCls(c), classNames.header) || undefined, style: c.width || c.pin ? { inlineSize: c.width, ...pinStyle(c) } : undefined, children: c.sortable ? _jsx("button", { type: "button", className: "k-table__sort", onClick: () => setSort(c.key), children: c.header }) : c.header }, c.key));
174
+ })] }) }), _jsx("tbody", { children: loadingRows > 0 ? (Array.from({ length: loadingRows }, (_, i) => (_jsxs("tr", { "aria-hidden": "true", children: [selectable && _jsx("td", { className: "k-table__check", children: _jsx("span", { className: "k-skeleton", style: { inlineSize: "1.125rem", blockSize: "1.125rem" } }) }), columns.map((c) => (_jsx("td", { className: cellCls(c), children: _jsx("span", { className: "k-skeleton", style: { inlineSize: `${50 + ((i * 17 + c.key.length * 11) % 40)}%` } }) }, c.key)))] }, `sk-${i}`)))) : sorted.length === 0 ? (_jsx("tr", { className: "k-table__empty", children: _jsx("td", { colSpan: colCount, children:
175
+ // متن ساده همان فاصله و ترازِ پیام پیش‌فرض را می‌گیرد؛ EmptyState یا عنصر دیگر خودش فاصله دارد
176
+ empty == null || typeof empty === "string" || typeof empty === "number"
177
+ ? _jsx("p", { style: { padding: "2rem", margin: 0, textAlign: "center" }, children: empty ?? M.table.empty })
178
+ : empty }) })) : (_jsxs(_Fragment, { children: [win && spacer(win.before, "sp-top"), visible.map((r, vi) => {
95
179
  const rid = getRowId(r);
96
180
  const on = sel.includes(rid);
97
181
  const index = (win?.first ?? 0) + vi;
98
182
  return (_jsxs("tr", { "data-row": vOpts ? "" : undefined, "aria-rowindex": vOpts ? index + 2 : undefined, className: cx(striped && vOpts && index % 2 === 1 && "k-table__row--odd", classNames.row) || undefined, "aria-selected": selectable ? on : undefined, onClick: onRowClick ? (e) => {
99
183
  // کلیک روی چک‌باکس، دکمه یا لینک داخل ردیف را ردیف نگیرد
100
- if (e.target.closest("a, button, input, label, select, textarea"))
184
+ if (e.target.closest("a, button, input, label, select, textarea, [role=button]"))
101
185
  return;
102
186
  onRowClick(r);
103
- } : undefined, children: [selectable && (_jsx("td", { className: "k-table__check", children: _jsx("input", { type: "checkbox", className: "k-checkbox", "aria-label": selectRow(r), checked: on, onChange: () => setSel(on ? sel.filter((x) => x !== rid) : [...sel, rid]) }) })), columns.map((c) => (_jsx("td", { className: cellCls(c), children: c.render ? c.render(r) : r[c.key] }, c.key)))] }, rid));
104
- }), win && spacer(win.after, "sp-bottom")] })) })] }), loadingRows > 0 && _jsx("span", { className: "k-sr-only", role: "status", children: loadingLabel }), footer && _jsx("div", { className: cx("k-table__footer", classNames.footer), children: footer })] }));
187
+ } : undefined, children: [selectable && (_jsx("td", { className: cx("k-table__check", pinStart && "k-table__pin"), style: pinStart ? { insetInlineStart: 0 } : undefined, children: _jsx("input", { type: "checkbox", className: "k-checkbox", "aria-label": selectRow(r), checked: on, onChange: () => setSel(on ? sel.filter((x) => x !== rid) : [...sel, rid]) }) })), columns.map((c) => {
188
+ const content = c.render ? c.render(r) : r[c.key];
189
+ const editHere = canEdit(c, r);
190
+ const isEditing = editing?.row === rid && editing.key === c.key;
191
+ const ck = `${rid}:${c.key}`;
192
+ return (_jsx("td", { className: cx(cellCls(c), pinCls(c), editHere && "k-table__cell--editable") || undefined, style: pinStyle(c), children: isEditing ? (_jsx("input", { className: "k-input k-table__editor", autoFocus: true, dir: c.numeric ? "ltr" : undefined, inputMode: (c.editType ?? (c.numeric ? "number" : "text")) === "number" ? "decimal" : undefined, "aria-label": M.table.edit(typeof c.header === "string" ? c.header : c.key, String(r[columns[0].key] ?? rid)), value: draft, onChange: (e) => setDraft(e.target.value), onFocus: (e) => e.currentTarget.select(), onKeyDown: (e) => {
193
+ if (e.key === "Enter") {
194
+ e.preventDefault();
195
+ finishEdit(r, c, true);
196
+ }
197
+ else if (e.key === "Escape") {
198
+ e.preventDefault();
199
+ e.stopPropagation();
200
+ finishEdit(r, c, false);
201
+ }
202
+ }, onBlur: () => finishEdit(r, c, true) })) : editHere ? (_jsx("div", { ref: (el) => { cellRefs.current.set(ck, el); }, className: "k-table__editable", role: "button", tabIndex: 0, "aria-describedby": hintId, onDoubleClick: () => startEdit(rid, c, r), onKeyDown: (e) => { if (e.key === "Enter" || e.key === "F2") {
203
+ e.preventDefault();
204
+ startEdit(rid, c, r);
205
+ } }, children: content })) : content }, c.key));
206
+ })] }, rid));
207
+ }), win && spacer(win.after, "sp-bottom")] })) })] }), loadingRows > 0 && _jsx("span", { className: "k-sr-only", role: "status", children: loadingLabel }), onCellEdit && _jsx("span", { className: "k-sr-only", id: hintId, children: M.table.editHint }), onCellEdit && _jsx("span", { className: "k-sr-only", "aria-live": "polite", children: live }), footer && _jsx("div", { className: cx("k-table__footer", classNames.footer), children: footer })] }));
105
208
  }
@@ -1,4 +1,5 @@
1
1
  import { type ReactNode } from "react";
2
+ import { type KashiMessages } from "@kashi-ui/persian";
2
3
  import { type CalendarLabels, type CalendarProps } from "./Calendar.js";
3
4
  export interface DateRange {
4
5
  start: Date | null;
@@ -12,6 +13,16 @@ export interface DateRangePreset {
12
13
  end: Date;
13
14
  };
14
15
  }
16
+ /**
17
+ * میان‌برهای گزارش‌گیری: امروز، ۷ و ۳۰ روز، این ماه و ماه قبل، فصل جاری و قبلی، سال مالی جاری و قبلی.
18
+ * startMonth ماه شروع سال مالی است (۱ = فروردین؛ برای سال مالی تیرماهی ۴).
19
+ */
20
+ export declare function fiscalRangePresets({ messages, n, startMonth, today }?: {
21
+ messages?: KashiMessages["dateRange"];
22
+ n?: (v: number) => string;
23
+ startMonth?: number;
24
+ today?: Date;
25
+ }): DateRangePreset[];
15
26
  /** میان‌برهای پیش‌فرض به فارسی؛ بدون presets، کامپوننت همین‌ها را به زبان KashiProvider نشان می‌دهد */
16
27
  export declare const defaultRangePresets: DateRangePreset[];
17
28
  export interface DateRangePickerProps {
@@ -26,6 +37,13 @@ export interface DateRangePickerProps {
26
37
  isDateDisabled?: (date: Date) => boolean;
27
38
  /** میان‌برهای کنار تقویم؛ [] برای حذف */
28
39
  presets?: DateRangePreset[];
40
+ /**
41
+ * میان‌برهای گزارش‌گیری: فصل جاری و قبلی و سال مالی جاری و قبلی هم اضافه می‌شوند.
42
+ * عدد = ماه شروع سال مالی (پیش‌فرض ۱، فروردین). وقتی presets داده شود اثری ندارد.
43
+ */
44
+ fiscalPresets?: boolean | number;
45
+ /** «امروز» برای میان‌برها (پیش‌فرض تاریخ دستگاه)؛ برای آزمون و نمایش ثابت */
46
+ today?: Date;
29
47
  /** @default "fa" */
30
48
  digits?: "fa" | "latin";
31
49
  /** با name، دو فیلد پنهان name_start و name_end به شکل YYYY-MM-DD ساخته می‌شود */
@@ -51,4 +69,4 @@ export interface DateRangePickerProps {
51
69
  * انتخاب بازهٔ تاریخ شمسی: کلیک اول شروع، کلیک دوم پایان؛ پیش از تأیید، بازه با حرکت موس پیش‌نمایش می‌شود.
52
70
  * تغییرها فقط با «تأیید» ثبت می‌شوند.
53
71
  */
54
- export declare function DateRangePicker({ label, hint, error, value, defaultValue, onChange, min, max, isDateDisabled, holidays, presets, digits, name, disabled, readOnly, id, className, calendarLabels, labels, }: DateRangePickerProps): import("react").JSX.Element;
72
+ export declare function DateRangePicker({ label, hint, error, value, defaultValue, onChange, min, max, isDateDisabled, holidays, presets, fiscalPresets, today: todayProp, digits, name, disabled, readOnly, id, className, calendarLabels, labels, }: DateRangePickerProps): import("react").JSX.Element;
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
3
  import { useEffect, useId, useRef, useState } from "react";
4
- import { faMessages, formatJalali, toFaDigits, toGregorian, toISODate, toJalali } from "@kashi-ui/persian";
4
+ import { faMessages, fiscalYearOf, fiscalYearRange, formatJalali, jalaliSeason, seasonRange, toFaDigits, toGregorian, toISODate, toJalali } from "@kashi-ui/persian";
5
5
  import { Calendar } from "./Calendar.js";
6
6
  import { Field } from "./Field.js";
7
7
  import { cx } from "./cx.js";
@@ -27,16 +27,37 @@ const presetsFor = (m, n) => [
27
27
  },
28
28
  },
29
29
  ];
30
+ const span = (r) => ({ start: r.from, end: r.to });
31
+ /**
32
+ * میان‌برهای گزارش‌گیری: امروز، ۷ و ۳۰ روز، این ماه و ماه قبل، فصل جاری و قبلی، سال مالی جاری و قبلی.
33
+ * startMonth ماه شروع سال مالی است (۱ = فروردین؛ برای سال مالی تیرماهی ۴).
34
+ */
35
+ export function fiscalRangePresets({ messages = faMessages.dateRange, n = (v) => toFaDigits(v), startMonth = 1, today = new Date() } = {}) {
36
+ const fy = fiscalYearOf(today, startMonth);
37
+ return [
38
+ { label: messages.today, range: (t) => ({ start: day(t), end: day(t) }) },
39
+ ...presetsFor(messages, n),
40
+ { label: messages.thisSeason, range: (t) => { const { jy, season } = jalaliSeason(t); return span(seasonRange(jy, season)); } },
41
+ {
42
+ label: messages.lastSeason,
43
+ range: (t) => { const { jy, season } = jalaliSeason(t); return span(season === 1 ? seasonRange(jy - 1, 4) : seasonRange(jy, season - 1)); },
44
+ },
45
+ { label: messages.fiscalYear(n(fy)), range: (t) => span(fiscalYearRange(fiscalYearOf(t, startMonth), startMonth)) },
46
+ { label: messages.fiscalYear(n(fy - 1)), range: (t) => span(fiscalYearRange(fiscalYearOf(t, startMonth) - 1, startMonth)) },
47
+ ];
48
+ }
30
49
  /** میان‌برهای پیش‌فرض به فارسی؛ بدون presets، کامپوننت همین‌ها را به زبان KashiProvider نشان می‌دهد */
31
50
  export const defaultRangePresets = presetsFor(faMessages.dateRange, (v) => toFaDigits(v));
32
51
  /**
33
52
  * انتخاب بازهٔ تاریخ شمسی: کلیک اول شروع، کلیک دوم پایان؛ پیش از تأیید، بازه با حرکت موس پیش‌نمایش می‌شود.
34
53
  * تغییرها فقط با «تأیید» ثبت می‌شوند.
35
54
  */
36
- export function DateRangePicker({ label, hint, error, value, defaultValue = { start: null, end: null }, onChange, min, max, isDateDisabled, holidays, presets, digits, name, disabled, readOnly, id, className, calendarLabels, labels = {}, }) {
55
+ export function DateRangePicker({ label, hint, error, value, defaultValue = { start: null, end: null }, onChange, min, max, isDateDisabled, holidays, presets, fiscalPresets, today: todayProp, digits, name, disabled, readOnly, id, className, calendarLabels, labels = {}, }) {
37
56
  const { messages: M, digits: D, locale, n: N } = useKashi();
38
57
  digits ?? (digits = D);
39
- presets ?? (presets = presetsFor(M.dateRange, N));
58
+ presets ?? (presets = fiscalPresets
59
+ ? fiscalRangePresets({ messages: M.dateRange, n: N, startMonth: typeof fiscalPresets === "number" ? fiscalPresets : 1, today: todayProp ?? new Date() })
60
+ : presetsFor(M.dateRange, N));
40
61
  const autoId = useId();
41
62
  const triggerId = id ?? autoId;
42
63
  const popoverId = `${triggerId}-popover`;
@@ -80,7 +101,7 @@ export function DateRangePicker({ label, hint, error, value, defaultValue = { st
80
101
  onChange?.(r);
81
102
  close();
82
103
  };
83
- const today = day(new Date());
104
+ const today = day(todayProp ?? new Date());
84
105
  const activePreset = presets.findIndex((p) => {
85
106
  const r = p.range(today);
86
107
  return draft.start?.getTime() === r.start.getTime() && draft.end?.getTime() === r.end.getTime();
@@ -0,0 +1,42 @@
1
+ import { type ReactNode } from "react";
2
+ export interface GanttTask {
3
+ id: string;
4
+ name: string;
5
+ start: Date;
6
+ /** روز پایان (شامل) */
7
+ end: Date;
8
+ /** درصد انجام‌شده (۰ تا ۱۰۰) */
9
+ progress?: number;
10
+ /** رنگ نوار؛ هر رنگ CSS یا توکن، مثل "var(--k-nemoodar-2)" */
11
+ color?: string;
12
+ /** شناسهٔ کارهایی که این کار بعد از آن‌ها شروع می‌شود */
13
+ dependsOn?: string[];
14
+ /** نقطهٔ عطف: یک روز، به شکل لوزی */
15
+ milestone?: boolean;
16
+ }
17
+ export interface GanttProps {
18
+ tasks: GanttTask[];
19
+ /** عنوان برای صفحه‌خوان */
20
+ label?: string;
21
+ /** روز اول و آخر نمودار؛ پیش‌فرض کمی پیش و پس از کارها */
22
+ from?: Date;
23
+ to?: Date;
24
+ /** امروز (برای خط امروز)؛ پیش‌فرض تاریخ دستگاه */
25
+ today?: Date;
26
+ /** جابه‌جا یا کشیدن نوار؛ بدون آن نمودار فقط‌خواندنی است */
27
+ onTaskChange?: (task: GanttTask, change: {
28
+ start: Date;
29
+ end: Date;
30
+ }) => void;
31
+ onTaskClick?: (task: GanttTask) => void;
32
+ /** تعطیلات رسمی ایران را هم مثل جمعه رنگ بزن @default true */
33
+ holidays?: boolean;
34
+ /** عنوان ستون کارها */
35
+ taskHeader?: ReactNode;
36
+ className?: string;
37
+ }
38
+ /**
39
+ * نمودار گانت با تقویم شمسی: سرستون ماه و روز شمسی، جمعه و تعطیلات رسمی، خط امروز، وابستگی کارها و پیشرفت هر کار.
40
+ * نوارها با ماوس و لمس جابه‌جا و کشیده می‌شوند و با کیبورد هم (جهت‌ها جابه‌جا، Shift + جهت طول).
41
+ */
42
+ export declare function Gantt({ tasks, label, from, to, today: todayProp, onTaskChange, onTaskClick, holidays, taskHeader, className }: GanttProps): import("react").JSX.Element;