@kashi-ui/react 2.24.1 → 2.26.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.
Files changed (117) hide show
  1. package/README.md +1 -1
  2. package/dist/ActivityHeatmap.js +4 -2
  3. package/dist/AddressForm.js +3 -2
  4. package/dist/Alert.js +3 -2
  5. package/dist/AppointmentPicker.js +4 -2
  6. package/dist/Avatar.js +5 -3
  7. package/dist/Badge.js +3 -2
  8. package/dist/BankBadge.js +2 -2
  9. package/dist/BankCard.js +4 -2
  10. package/dist/Banner.js +3 -2
  11. package/dist/BillInput.d.ts +39 -0
  12. package/dist/BillInput.js +57 -0
  13. package/dist/BottomSheet.js +3 -2
  14. package/dist/Breadcrumb.js +3 -2
  15. package/dist/BusinessHours.js +6 -3
  16. package/dist/Button.js +3 -2
  17. package/dist/Calendar.js +4 -2
  18. package/dist/CardNumberInput.js +4 -2
  19. package/dist/Carousel.js +4 -2
  20. package/dist/Chart.js +6 -4
  21. package/dist/Chat.js +6 -4
  22. package/dist/ChatComposer.js +4 -2
  23. package/dist/CitySelect.js +3 -2
  24. package/dist/CodeBlock.js +4 -2
  25. package/dist/ColorPicker.js +6 -3
  26. package/dist/Combobox.d.ts +4 -0
  27. package/dist/Combobox.js +11 -6
  28. package/dist/CommandPalette.js +4 -2
  29. package/dist/ContextMenu.js +3 -2
  30. package/dist/CopyButton.js +3 -2
  31. package/dist/Countdown.js +4 -2
  32. package/dist/DataTable.d.ts +19 -1
  33. package/dist/DataTable.js +109 -9
  34. package/dist/DatePicker.js +4 -2
  35. package/dist/DateRangePicker.d.ts +19 -1
  36. package/dist/DateRangePicker.js +30 -7
  37. package/dist/DateTile.js +2 -2
  38. package/dist/Dialog.js +3 -2
  39. package/dist/Drawer.js +3 -2
  40. package/dist/EconomicCodeInput.js +4 -2
  41. package/dist/EmptyState.js +3 -2
  42. package/dist/Field.js +3 -2
  43. package/dist/FileUpload.d.ts +1 -1
  44. package/dist/FileUpload.js +9 -6
  45. package/dist/Gantt.d.ts +42 -0
  46. package/dist/Gantt.js +118 -0
  47. package/dist/IbanInput.js +3 -2
  48. package/dist/ImageCropper.d.ts +56 -0
  49. package/dist/ImageCropper.js +187 -0
  50. package/dist/InfiniteScroll.d.ts +34 -0
  51. package/dist/InfiniteScroll.js +46 -0
  52. package/dist/InlineEdit.js +3 -2
  53. package/dist/Input.js +3 -2
  54. package/dist/Invoice.d.ts +65 -0
  55. package/dist/Invoice.js +32 -0
  56. package/dist/IranMap.js +4 -2
  57. package/dist/Kanban.js +4 -2
  58. package/dist/KashiProvider.d.ts +731 -3
  59. package/dist/KashiProvider.js +19 -4
  60. package/dist/KeyboardFixInput.js +4 -2
  61. package/dist/LandlineInput.js +4 -2
  62. package/dist/LegalIdInput.js +4 -2
  63. package/dist/Lightbox.js +6 -3
  64. package/dist/Meter.js +4 -2
  65. package/dist/MobileInput.js +4 -2
  66. package/dist/Money.js +4 -2
  67. package/dist/MonthPicker.js +4 -2
  68. package/dist/MultiSelect.js +4 -2
  69. package/dist/NationalIdInput.js +4 -2
  70. package/dist/Navbar.js +3 -2
  71. package/dist/NotificationCenter.js +6 -3
  72. package/dist/NumberInput.js +4 -2
  73. package/dist/OtpInput.js +2 -2
  74. package/dist/Pagination.js +4 -2
  75. package/dist/PasswordStrength.js +5 -4
  76. package/dist/PaymentReceipt.js +4 -2
  77. package/dist/PersianInput.d.ts +3 -0
  78. package/dist/PersianInput.js +8 -2
  79. package/dist/PersianTextarea.js +4 -2
  80. package/dist/PlateInput.js +3 -2
  81. package/dist/PostalCodeInput.js +4 -2
  82. package/dist/PriceInput.js +4 -2
  83. package/dist/PriceRange.js +4 -2
  84. package/dist/Progress.js +5 -3
  85. package/dist/ProvinceSelect.js +3 -2
  86. package/dist/QRCode.js +3 -2
  87. package/dist/Rating.js +4 -2
  88. package/dist/RelativeTime.js +2 -2
  89. package/dist/RichTextEditor.js +4 -2
  90. package/dist/SayadInput.js +4 -2
  91. package/dist/Scheduler.js +4 -2
  92. package/dist/SearchSuggest.js +6 -4
  93. package/dist/Select.js +3 -2
  94. package/dist/SideNav.js +3 -2
  95. package/dist/SignaturePad.d.ts +38 -0
  96. package/dist/SignaturePad.js +170 -0
  97. package/dist/Slider.js +4 -2
  98. package/dist/Sortable.js +4 -2
  99. package/dist/Splitter.js +4 -2
  100. package/dist/Stat.js +4 -2
  101. package/dist/Stepper.js +4 -2
  102. package/dist/StreamingText.js +3 -2
  103. package/dist/SwatchGroup.js +3 -2
  104. package/dist/TagInput.js +4 -2
  105. package/dist/TaxIdInput.js +3 -2
  106. package/dist/TimeClock.js +4 -2
  107. package/dist/TimeInput.js +4 -2
  108. package/dist/TimePicker.js +4 -2
  109. package/dist/Toast.js +3 -2
  110. package/dist/Tour.js +4 -2
  111. package/dist/VirtualList.d.ts +35 -0
  112. package/dist/VirtualList.js +104 -0
  113. package/dist/index.d.ts +19 -1
  114. package/dist/index.js +10 -1
  115. package/dist/xlsx.d.ts +5 -0
  116. package/dist/xlsx.js +14 -0
  117. package/package.json +4 -4
package/dist/Combobox.js CHANGED
@@ -1,18 +1,22 @@
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
- import { useKashi } from "./KashiProvider.js";
8
+ import { useKashiLocale, useMessages } from "./KashiProvider.js";
9
+ import { faCombobox, faCommon } from "@kashi-ui/persian";
9
10
  /** متن یکدست برای جستجو: ي/ی، ك/ک، ارقام، حروف کوچک */
10
11
  export const searchText = (s) => normalizePersian(s, { digits: "latin" }).toLowerCase();
12
+ /**
13
+ * فیلتر پیش‌فرض با جستجوی فارسی کاشی (persianMatch): ي/ی و ك/ک یکی‌اند، نیم‌فاصله نادیده گرفته می‌شود،
14
+ * «mamad» «ممد» را پیدا می‌کند و متنی که با چیدمان انگلیسی صفحه‌کلید تایپ شده («hdvhk») هم «ایران» را.
15
+ */
11
16
  export function defaultFilter(option, query) {
12
- const q = searchText(query.trim());
13
- if (!q)
17
+ if (!query.trim())
14
18
  return true;
15
- return [option.label, option.description ?? "", ...(option.keywords ?? [])].some((t) => searchText(t).includes(q));
19
+ return [option.label, option.description ?? "", ...(option.keywords ?? [])].some((t) => persianMatch(query, t) > 0);
16
20
  }
17
21
  /** بخش منطبق با جستجو را با <mark> برجسته می‌کند */
18
22
  export function highlight(text, query) {
@@ -31,7 +35,8 @@ const Check = () => (_jsx("svg", { viewBox: "0 0 20 20", fill: "none", stroke: "
31
35
  * جستجو «علي» و «علی» را یکی می‌داند.
32
36
  */
33
37
  export const Combobox = forwardRef(function Combobox({ label, hint, error, options, value, defaultValue = null, onChange, onInputChange, placeholder, filter = defaultFilter, emptyMessage, loading, required, disabled, readOnly, name, id, className, resultsLabel, }, ref) {
34
- const { messages: M, n: N } = useKashi();
38
+ const M = useMessages({ combobox: faCombobox, common: faCommon });
39
+ const { n: N } = useKashiLocale();
35
40
  emptyMessage ?? (emptyMessage = M.common.noResults);
36
41
  resultsLabel ?? (resultsLabel = (x) => M.common.results(N(x)));
37
42
  const autoId = useId();
@@ -3,13 +3,15 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { useEffect, useId, useMemo, useRef, useState } from "react";
4
4
  import { defaultFilter, highlight } from "./Combobox.js";
5
5
  import { cx } from "./cx.js";
6
- import { useKashi } from "./KashiProvider.js";
6
+ import { useKashiLocale, useMessages } from "./KashiProvider.js";
7
+ import { faCommand, faCommon } from "@kashi-ui/persian";
7
8
  /**
8
9
  * پالت فرمان: جستجوی سریع در عمل‌ها و صفحه‌ها با Ctrl+K.
9
10
  * پنجره روی <dialog> بومی است (تلهٔ فوکوس و Esc) و فهرست با الگوی combobox/listbox پیمایش می‌شود.
10
11
  */
11
12
  export function CommandPalette({ open, onOpenChange, items, shortcut = true, placeholder, emptyMessage, labels = {}, className, }) {
12
- const { messages: M, n: N } = useKashi();
13
+ const M = useMessages({ command: faCommand, common: faCommon });
14
+ const { n: N } = useKashiLocale();
13
15
  placeholder ?? (placeholder = M.command.placeholder);
14
16
  emptyMessage ?? (emptyMessage = M.command.empty);
15
17
  const id = useId();
@@ -3,13 +3,14 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { useEffect, useId, useRef, useState } from "react";
4
4
  import { MenuCtx, items, menuKeyDown } from "./DropdownMenu.js";
5
5
  import { cx } from "./cx.js";
6
- import { useKashi } from "./KashiProvider.js";
6
+ import { useMessages } from "./KashiProvider.js";
7
+ import { faContextMenu } from "@kashi-ui/persian";
7
8
  /**
8
9
  * منوی راست‌کلیک؛ با کیبورد هم: کلید ContextMenu یا Shift+F10 روی ناحیهٔ فوکوس‌شده.
9
10
  * همان گزینه‌ها و پیمایش منوی کشویی را دارد.
10
11
  */
11
12
  export function ContextMenu({ children, menu, label, className }) {
12
- const { messages: M } = useKashi();
13
+ const M = useMessages({ contextMenu: faContextMenu });
13
14
  label ?? (label = M.contextMenu.label);
14
15
  const id = useId();
15
16
  const [pos, setPos] = useState(null);
@@ -2,12 +2,13 @@
2
2
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
3
  import { useEffect, useRef, useState } from "react";
4
4
  import { Button } from "./Button.js";
5
- import { useKashi } from "./KashiProvider.js";
5
+ import { useMessages } from "./KashiProvider.js";
6
+ import { faCopy } from "@kashi-ui/persian";
6
7
  const CopyIcon = () => (_jsxs("svg", { viewBox: "0 0 20 20", fill: "none", stroke: "currentColor", strokeWidth: 1.7, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: [_jsx("rect", { x: "7", y: "7", width: "10", height: "10", rx: "2" }), _jsx("path", { d: "M13 7V5a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v6a2 2 0 0 0 2 2h2" })] }));
7
8
  const CheckIcon = () => (_jsx("svg", { viewBox: "0 0 20 20", fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: _jsx("path", { d: "m5 10.5 3.2 3L15 7" }) }));
8
9
  /** دکمهٔ کپی در کلیپ‌بورد با بازخورد «کپی شد» برای چشم و صفحه‌خوان */
9
10
  export function CopyButton({ value, onCopy, iconOnly, timeout = 2000, labels = {}, variant = "secondary", size = "sm", ...rest }) {
10
- const { messages: M } = useKashi();
11
+ const M = useMessages({ copy: faCopy });
11
12
  const { copy = M.copy.copy, copied = M.copy.copied, failed = M.copy.failed } = labels;
12
13
  const [state, setState] = useState("idle");
13
14
  const timer = useRef(undefined);
package/dist/Countdown.js CHANGED
@@ -3,11 +3,13 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { useEffect, useRef, useState } from "react";
4
4
  import { toFaDigits } from "@kashi-ui/persian";
5
5
  import { cx } from "./cx.js";
6
- import { useKashi } from "./KashiProvider.js";
6
+ import { useKashiLocale, useMessages } from "./KashiProvider.js";
7
+ import { faCommon, faCountdown } from "@kashi-ui/persian";
7
8
  const pad = (n) => String(n).padStart(2, "0");
8
9
  /** شمارش معکوس با ارقام فارسی؛ هر ثانیه به‌روز می‌شود و در پایان onComplete را صدا می‌زند */
9
10
  export function Countdown({ to, seconds, onComplete, variant = "clock", digits, "aria-label": ariaLabel, className, labels = {} }) {
10
- const { messages: M, digits: D } = useKashi();
11
+ const M = useMessages({ common: faCommon, countdown: faCountdown });
12
+ const { digits: D } = useKashiLocale();
11
13
  digits ?? (digits = D);
12
14
  const { days = M.countdown.days, hours = M.countdown.hours, minutes = M.countdown.minutes, seconds: secLabel = M.countdown.seconds } = labels;
13
15
  const end = useRef(to?.getTime() ?? Date.now() + (seconds ?? 0) * 1000);
@@ -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,12 @@
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
- import { useKashi } from "./KashiProvider.js";
6
+ import { useMessages } from "./KashiProvider.js";
7
+ import { faCommon, faTable } from "@kashi-ui/persian";
6
8
  /** جدول داده با مرتب‌سازی (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, }) {
9
+ 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
10
  const id = useId();
9
11
  const [innerSort, setInnerSort] = useState(defaultSort);
10
12
  const [innerSel, setInnerSel] = useState([]);
@@ -41,11 +43,81 @@ export function DataTable({ columns, rows, getRowId, caption, description, hideC
41
43
  if (allRef.current)
42
44
  allRef.current.indeterminate = some;
43
45
  }, [some]);
44
- const { messages: M } = useKashi();
46
+ const M = useMessages({ common: faCommon, table: faTable });
45
47
  const { selectAll = M.table.selectAll, selectRow = () => M.table.selectRow, loading: loadingLabel = M.common.loading } = labels;
46
48
  const loadingRows = loading === true ? 5 : typeof loading === "number" ? loading : 0;
47
49
  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
50
  const colCount = columns.length + (selectable ? 1 : 0);
51
+ // ---- ستون‌های ثابت: جای هر ستون از پهنای واقعی ستون‌های پیش از آن
52
+ const heads = useRef(new Map());
53
+ const checkHead = useRef(null);
54
+ const hasPin = columns.some((c) => c.pin);
55
+ const pinStart = columns.some((c) => c.pin === "start");
56
+ const [pinOff, setPinOff] = useState({});
57
+ const measurePins = useCallback(() => {
58
+ if (!hasPin)
59
+ return;
60
+ const next = {};
61
+ let acc = selectable && pinStart ? (checkHead.current?.offsetWidth ?? 0) : 0;
62
+ for (const c of columns)
63
+ if (c.pin === "start") {
64
+ next[c.key] = acc;
65
+ acc += heads.current.get(c.key)?.offsetWidth ?? 0;
66
+ }
67
+ acc = 0;
68
+ for (const c of [...columns].reverse())
69
+ if (c.pin === "end") {
70
+ next[c.key] = acc;
71
+ acc += heads.current.get(c.key)?.offsetWidth ?? 0;
72
+ }
73
+ setPinOff((old) => (Object.keys(next).every((k) => old[k] === next[k]) && Object.keys(old).length === Object.keys(next).length ? old : next));
74
+ }, [hasPin, pinStart, selectable, columns]);
75
+ const lastStart = [...columns].reverse().find((c) => c.pin === "start")?.key;
76
+ const firstEnd = columns.find((c) => c.pin === "end")?.key;
77
+ const pinStyle = (c) => (c.pin ? { [c.pin === "start" ? "insetInlineStart" : "insetInlineEnd"]: pinOff[c.key] ?? 0 } : undefined);
78
+ const pinCls = (c) => c.pin && cx("k-table__pin", (c.key === lastStart || c.key === firstEnd) && `k-table__pin--edge-${c.pin}`);
79
+ // ---- ویرایش داخل خانه
80
+ const [editing, setEditing] = useState(null);
81
+ const [draft, setDraft] = useState("");
82
+ const [live, setLive] = useState("");
83
+ const refocus = useRef(null);
84
+ const cellRefs = useRef(new Map());
85
+ const canEdit = (c, r) => !!onCellEdit && (typeof c.editable === "function" ? c.editable(r) : !!c.editable);
86
+ const startEdit = (rid, c, r) => {
87
+ const v = c.sortValue ? c.sortValue(r) : r[c.key];
88
+ setDraft(v == null ? "" : String(v));
89
+ setEditing({ row: rid, key: c.key });
90
+ };
91
+ const finishEdit = (r, c, save) => {
92
+ if (!editing)
93
+ return;
94
+ refocus.current = `${editing.row}:${editing.key}`;
95
+ setEditing(null);
96
+ if (!save)
97
+ return;
98
+ const type = c.editType ?? (c.numeric ? "number" : "text");
99
+ const raw = type === "number" ? toEnDigits(draft).replace(/[٬,\s]/g, "") : draft;
100
+ const value = type === "number" && raw !== "" && Number.isFinite(Number(raw)) ? Number(raw) : raw;
101
+ onCellEdit?.(r, c.key, value);
102
+ setLive(M.table.saved);
103
+ };
104
+ useEffect(() => {
105
+ if (!editing && refocus.current) {
106
+ cellRefs.current.get(refocus.current)?.focus();
107
+ refocus.current = null;
108
+ }
109
+ }, [editing]);
110
+ const hintId = `${id}-edit-hint`;
111
+ const exportExcel = async () => {
112
+ const { downloadXlsx } = await import("./xlsx.js");
113
+ const opts = typeof exportable === "object" ? exportable : {};
114
+ const header = columns.map((c) => c.exportHeader ?? (typeof c.header === "string" || typeof c.header === "number" ? String(c.header) : c.key));
115
+ const data = sorted.map((r) => columns.map((c) => {
116
+ const v = c.exportValue ? c.exportValue(r) : r[c.key];
117
+ return v == null || typeof v === "string" || typeof v === "number" || typeof v === "boolean" || v instanceof Date ? v : String(v);
118
+ }));
119
+ downloadXlsx(opts.fileName ?? "kashi-table", header, data, { sheetName: opts.sheetName });
120
+ };
49
121
  // ---- اسکرول مجازی
50
122
  const vOpts = virtual ? (typeof virtual === "object" ? virtual : {}) : null;
51
123
  const wrap = useRef(null);
@@ -70,6 +142,15 @@ export function DataTable({ columns, rows, getRowId, caption, description, hideC
70
142
  return () => { w.removeEventListener("scroll", on); ro?.disconnect(); cancelAnimationFrame(frame); };
71
143
  }, [!!vOpts]);
72
144
  const useIso = typeof window === "undefined" ? useEffect : useLayoutEffect;
145
+ useIso(() => { measurePins(); });
146
+ useEffect(() => {
147
+ const t = wrap.current?.querySelector("table");
148
+ if (!hasPin || !t || typeof ResizeObserver === "undefined")
149
+ return;
150
+ const ro = new ResizeObserver(() => measurePins());
151
+ ro.observe(t);
152
+ return () => ro.disconnect();
153
+ }, [hasPin, measurePins]);
73
154
  useIso(() => {
74
155
  // ارتفاع واقعی ردیف را از اولین ردیف ساخته‌شده بخوان
75
156
  if (!vOpts || vOpts.rowHeight)
@@ -88,9 +169,9 @@ export function DataTable({ columns, rows, getRowId, caption, description, hideC
88
169
  : null;
89
170
  const visible = win ? sorted.slice(win.first, win.last) : sorted;
90
171
  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) => {
172
+ 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
173
  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));
174
+ 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));
94
175
  })] }) }), _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:
95
176
  // متن ساده همان فاصله و ترازِ پیام پیش‌فرض را می‌گیرد؛ EmptyState یا عنصر دیگر خودش فاصله دارد
96
177
  empty == null || typeof empty === "string" || typeof empty === "number"
@@ -101,9 +182,28 @@ export function DataTable({ columns, rows, getRowId, caption, description, hideC
101
182
  const index = (win?.first ?? 0) + vi;
102
183
  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) => {
103
184
  // کلیک روی چک‌باکس، دکمه یا لینک داخل ردیف را ردیف نگیرد
104
- if (e.target.closest("a, button, input, label, select, textarea"))
185
+ if (e.target.closest("a, button, input, label, select, textarea, [role=button]"))
105
186
  return;
106
187
  onRowClick(r);
107
- } : 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));
108
- }), 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 })] }));
188
+ } : 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) => {
189
+ const content = c.render ? c.render(r) : r[c.key];
190
+ const editHere = canEdit(c, r);
191
+ const isEditing = editing?.row === rid && editing.key === c.key;
192
+ const ck = `${rid}:${c.key}`;
193
+ 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) => {
194
+ if (e.key === "Enter") {
195
+ e.preventDefault();
196
+ finishEdit(r, c, true);
197
+ }
198
+ else if (e.key === "Escape") {
199
+ e.preventDefault();
200
+ e.stopPropagation();
201
+ finishEdit(r, c, false);
202
+ }
203
+ }, 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") {
204
+ e.preventDefault();
205
+ startEdit(rid, c, r);
206
+ } }, children: content })) : content }, c.key));
207
+ })] }, rid));
208
+ }), 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 })] }));
109
209
  }
@@ -5,13 +5,15 @@ import { formatJalali, parseJalali, toISODate } from "@kashi-ui/persian";
5
5
  import { Calendar, sameDay } from "./Calendar.js";
6
6
  import { Input } from "./Input.js";
7
7
  import { mergeRefs, useIsomorphicLayoutEffect } from "./utils.js";
8
- import { useKashi } from "./KashiProvider.js";
8
+ import { useKashiLocale, useMessages } from "./KashiProvider.js";
9
+ import { faCommon, faDatePicker } from "@kashi-ui/persian";
9
10
  /**
10
11
  * انتخاب تاریخ شمسی: تایپ مستقیم (۱۴۰۳/۰۵/۱۲) یا انتخاب از تقویم.
11
12
  * با name، مقدار میلادی به شکل YYYY-MM-DD در فرم ارسال می‌شود.
12
13
  */
13
14
  export const DatePicker = forwardRef(function DatePicker({ value, defaultValue = null, onChange, min, max, isDateDisabled, holidays, digits, yearRange, invalidMessage, openLabel, todayLabel, calendarLabels, error, name, onBlur, placeholder, readOnly, ...rest }, ref) {
14
- const { messages: M, digits: D, locale } = useKashi();
15
+ const M = useMessages({ common: faCommon, datePicker: faDatePicker });
16
+ const { digits: D, locale } = useKashiLocale();
15
17
  digits ?? (digits = D);
16
18
  invalidMessage ?? (invalidMessage = M.datePicker.invalid);
17
19
  openLabel ?? (openLabel = M.datePicker.open);
@@ -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,11 +1,12 @@
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 { faDateRange, 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";
8
- import { useKashi } from "./KashiProvider.js";
8
+ import { useKashiLocale, useMessages } from "./KashiProvider.js";
9
+ import { faCommon } from "@kashi-ui/persian";
9
10
  const day = (d, add = 0) => new Date(d.getFullYear(), d.getMonth(), d.getDate() + add);
10
11
  /** میان‌برهای پیش‌فرض با ماه‌های شمسی، با متن‌های یک زبان */
11
12
  const presetsFor = (m, n) => [
@@ -27,16 +28,38 @@ const presetsFor = (m, n) => [
27
28
  },
28
29
  },
29
30
  ];
31
+ const span = (r) => ({ start: r.from, end: r.to });
32
+ /**
33
+ * میان‌برهای گزارش‌گیری: امروز، ۷ و ۳۰ روز، این ماه و ماه قبل، فصل جاری و قبلی، سال مالی جاری و قبلی.
34
+ * startMonth ماه شروع سال مالی است (۱ = فروردین؛ برای سال مالی تیرماهی ۴).
35
+ */
36
+ export function fiscalRangePresets({ messages = faDateRange, n = (v) => toFaDigits(v), startMonth = 1, today = new Date() } = {}) {
37
+ const fy = fiscalYearOf(today, startMonth);
38
+ return [
39
+ { label: messages.today, range: (t) => ({ start: day(t), end: day(t) }) },
40
+ ...presetsFor(messages, n),
41
+ { label: messages.thisSeason, range: (t) => { const { jy, season } = jalaliSeason(t); return span(seasonRange(jy, season)); } },
42
+ {
43
+ label: messages.lastSeason,
44
+ range: (t) => { const { jy, season } = jalaliSeason(t); return span(season === 1 ? seasonRange(jy - 1, 4) : seasonRange(jy, season - 1)); },
45
+ },
46
+ { label: messages.fiscalYear(n(fy)), range: (t) => span(fiscalYearRange(fiscalYearOf(t, startMonth), startMonth)) },
47
+ { label: messages.fiscalYear(n(fy - 1)), range: (t) => span(fiscalYearRange(fiscalYearOf(t, startMonth) - 1, startMonth)) },
48
+ ];
49
+ }
30
50
  /** میان‌برهای پیش‌فرض به فارسی؛ بدون presets، کامپوننت همین‌ها را به زبان KashiProvider نشان می‌دهد */
31
- export const defaultRangePresets = presetsFor(faMessages.dateRange, (v) => toFaDigits(v));
51
+ export const defaultRangePresets = presetsFor(faDateRange, (v) => toFaDigits(v));
32
52
  /**
33
53
  * انتخاب بازهٔ تاریخ شمسی: کلیک اول شروع، کلیک دوم پایان؛ پیش از تأیید، بازه با حرکت موس پیش‌نمایش می‌شود.
34
54
  * تغییرها فقط با «تأیید» ثبت می‌شوند.
35
55
  */
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 = {}, }) {
37
- const { messages: M, digits: D, locale, n: N } = useKashi();
56
+ 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 = {}, }) {
57
+ const M = useMessages({ common: faCommon, dateRange: faDateRange });
58
+ const { digits: D, locale, n: N } = useKashiLocale();
38
59
  digits ?? (digits = D);
39
- presets ?? (presets = presetsFor(M.dateRange, N));
60
+ presets ?? (presets = fiscalPresets
61
+ ? fiscalRangePresets({ messages: M.dateRange, n: N, startMonth: typeof fiscalPresets === "number" ? fiscalPresets : 1, today: todayProp ?? new Date() })
62
+ : presetsFor(M.dateRange, N));
40
63
  const autoId = useId();
41
64
  const triggerId = id ?? autoId;
42
65
  const popoverId = `${triggerId}-popover`;
@@ -80,7 +103,7 @@ export function DateRangePicker({ label, hint, error, value, defaultValue = { st
80
103
  onChange?.(r);
81
104
  close();
82
105
  };
83
- const today = day(new Date());
106
+ const today = day(todayProp ?? new Date());
84
107
  const activePreset = presets.findIndex((p) => {
85
108
  const r = p.range(today);
86
109
  return draft.start?.getTime() === r.start.getTime() && draft.end?.getTime() === r.end.getTime();
package/dist/DateTile.js CHANGED
@@ -3,13 +3,13 @@ import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
3
3
  import { forwardRef } from "react";
4
4
  import { getIranHoliday, jalaliWeekday, toISODate, toJalali } from "@kashi-ui/persian";
5
5
  import { cx } from "./cx.js";
6
- import { useKashi } from "./KashiProvider.js";
6
+ import { useKashiLocale } from "./KashiProvider.js";
7
7
  const gregFmt = new Intl.DateTimeFormat("fa-IR-u-ca-gregory-nu-arabext", { day: "numeric", month: "long", year: "numeric" });
8
8
  const gregFmtEn = new Intl.DateTimeFormat("en-US", { day: "numeric", month: "long", year: "numeric" });
9
9
  /** کاشی تاریخ شمسی به شکل برگ تقویم: روز، ماه، روز هفته، مناسبت تعطیل و معادل میلادی */
10
10
  export const DateTile = forwardRef(function DateTile({ date, holidays = true, gregorian = true, size = "md", className, ...rest }, ref) {
11
11
  const { jy, jm, jd } = toJalali(date);
12
- const { n, locale, months: MONTHS, weekdays: WD, friday: FRI } = useKashi();
12
+ const { n, locale, months: MONTHS, weekdays: WD, friday: FRI } = useKashiLocale();
13
13
  const holiday = holidays ? getIranHoliday(date, holidays === true ? { locale } : { locale, ...holidays }) : null;
14
14
  const occasion = holiday && holiday !== FRI ? holiday : null;
15
15
  return (_jsxs("time", { ref: ref, dateTime: toISODate(date), className: cx("k-datetile", `k-datetile--${size}`, className), "data-holiday": holiday ? "" : undefined, ...rest, children: [_jsxs("span", { className: "k-datetile__head", children: [MONTHS[jm - 1], " ", n(jy)] }), _jsx("span", { className: "k-datetile__day", children: n(jd) }), _jsx("span", { className: "k-datetile__weekday", children: WD[jalaliWeekday(date)] }), occasion && _jsx("span", { className: "k-datetile__occasion", children: occasion }), gregorian && _jsx("span", { className: "k-datetile__greg", children: (locale === "en" ? gregFmtEn : gregFmt).format(date) })] }));
package/dist/Dialog.js CHANGED
@@ -3,7 +3,8 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { useId, useRef } from "react";
4
4
  import { cx } from "./cx.js";
5
5
  import { CloseIcon } from "./icons.js";
6
- import { useKashi } from "./KashiProvider.js";
6
+ import { useMessages } from "./KashiProvider.js";
7
+ import { faCommon } from "@kashi-ui/persian";
7
8
  import { useModalDialog } from "./modal.js";
8
9
  /**
9
10
  * پنجرهٔ گفتگو روی <dialog> بومی با showModal:
@@ -11,7 +12,7 @@ import { useModalDialog } from "./modal.js";
11
12
  * و پس از بستن، فوکوس به عنصری که پنجره را باز کرده برمی‌گردد.
12
13
  */
13
14
  export function Dialog({ open, onOpenChange, title, description, icon, tone = "default", size = "md", footer, dismissible = true, closeLabel, placement = "center", className, children, }) {
14
- const { messages: M } = useKashi();
15
+ const M = useMessages({ common: faCommon });
15
16
  closeLabel ?? (closeLabel = M.common.close);
16
17
  const ref = useRef(null);
17
18
  const id = useId();
package/dist/Drawer.js CHANGED
@@ -3,14 +3,15 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { useId, useRef } from "react";
4
4
  import { cx } from "./cx.js";
5
5
  import { CloseIcon } from "./icons.js";
6
- import { useKashi } from "./KashiProvider.js";
6
+ import { useMessages } from "./KashiProvider.js";
7
+ import { faCommon } from "@kashi-ui/persian";
7
8
  import { useModalDialog } from "./modal.js";
8
9
  /**
9
10
  * کشوی کناری روی <dialog> بومی: فیلترها، جزئیات یک ردیف، تنظیمات یا منوی گوشی.
10
11
  * فوکوس داخل کشو می‌ماند، Esc می‌بندد و با انیمیشن خروج بسته می‌شود.
11
12
  */
12
13
  export function Drawer({ open, onOpenChange, title, description, side = "end", size = "md", footer, dismissible = true, closeLabel, className, children, }) {
13
- const { messages: M } = useKashi();
14
+ const M = useMessages({ common: faCommon });
14
15
  closeLabel ?? (closeLabel = M.common.close);
15
16
  const ref = useRef(null);
16
17
  const id = useId();
@@ -5,13 +5,15 @@ import { economicCodeType, isValidEconomicCode } from "@kashi-ui/persian";
5
5
  import { Input } from "./Input.js";
6
6
  import { useDigitsInput } from "./useDigitsInput.js";
7
7
  import { mergeRefs } from "./utils.js";
8
- import { useKashi } from "./KashiProvider.js";
8
+ import { useKashiLocale, useMessages } from "./KashiProvider.js";
9
+ import { faInvalid, faTaxCode } from "@kashi-ui/persian";
9
10
  /**
10
11
  * کد اقتصادی فاکتور: ۱۰ رقم (کد ملی شخص حقیقی)، ۱۱ رقم (شناسهٔ ملی شخص حقوقی) یا ۱۲ رقم قدیمی.
11
12
  * کد ملی و شناسهٔ ملی با رقم کنترل خودشان بررسی می‌شوند و نوع کنار فیلد می‌آید.
12
13
  */
13
14
  export const EconomicCodeInput = forwardRef(function EconomicCodeInput({ value, defaultValue, onValueChange, showType = true, digits, invalidMessage, error, name, onBlur, placeholder, ...rest }, ref) {
14
- const { messages: M, digits: D } = useKashi();
15
+ const M = useMessages({ invalid: faInvalid, taxCode: faTaxCode });
16
+ const { digits: D } = useKashiLocale();
15
17
  digits ?? (digits = D);
16
18
  invalidMessage ?? (invalidMessage = M.invalid.economicCode);
17
19
  const { raw, shown, inputRef, handleChange } = useDigitsInput({ value, defaultValue, maxDigits: 12, format: (d) => d, digits });
@@ -1,7 +1,8 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { cx } from "./cx.js";
4
- import { useKashi } from "./KashiProvider.js";
4
+ import { useMessages } from "./KashiProvider.js";
5
+ import { faEmpty } from "@kashi-ui/persian";
5
6
  const P = { viewBox: "0 0 20 20", fill: "none", stroke: "currentColor", strokeWidth: 1.5, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": true };
6
7
  // آیکون‌ها از @kashi-ui/icons، کپی‌شده تا پکیج React به آن وابسته نشود
7
8
  const ICONS = {
@@ -14,7 +15,7 @@ const ICONS = {
14
15
  };
15
16
  /** حالت خالی: وقتی داده‌ای برای نمایش نیست؛ بگویید چرا و قدم بعدی را پیشنهاد کنید */
16
17
  export function EmptyState({ title, description, icon, actions, preset, size = "md", bordered, className, ...rest }) {
17
- const { messages: M } = useKashi();
18
+ const M = useMessages({ empty: faEmpty });
18
19
  const text = preset ? M.empty[preset] : undefined;
19
20
  title ?? (title = text?.[0]);
20
21
  description ?? (description = text?.[1]);
package/dist/Field.js CHANGED
@@ -1,7 +1,8 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { cx } from "./cx.js";
4
- import { useKashi } from "./KashiProvider.js";
4
+ import { useMessages } from "./KashiProvider.js";
5
+ import { faCommon } from "@kashi-ui/persian";
5
6
  /** شناسهٔ متن‌های راهنما و خطا برای aria-describedby */
6
7
  export const hintId = (id) => `${id}-hint`;
7
8
  export const errorId = (id) => `${id}-error`;
@@ -10,7 +11,7 @@ export function describedBy(id, hint, error, extra) {
10
11
  }
11
12
  /** قالب مشترک برچسب + کنترل + راهنما/خطا */
12
13
  export function Field({ id, label, hint, error, required, optional, labelEnd, hintEnd, className, classNames = {}, children }) {
13
- const { messages: M } = useKashi();
14
+ const M = useMessages({ common: faCommon });
14
15
  const optionalText = optional === true ? M.common.optional : optional;
15
16
  return (_jsxs("div", { className: cx("k-field", className, classNames.root), "data-invalid": error ? "" : undefined, children: [(label || labelEnd) && (_jsxs("div", { className: "k-field__label-row", children: [label && (_jsxs("label", { className: cx("k-label", classNames.label), htmlFor: id, children: [label, required && _jsx("span", { className: "k-label__required", "aria-hidden": "true", children: "*" }), optionalText && _jsx("span", { className: "k-label__optional", children: optionalText })] })), labelEnd && _jsx("span", { className: "k-field__label-end", children: labelEnd })] })), children, (error || hint || hintEnd) && (_jsxs("div", { className: "k-field__hint-row", children: [_jsxs("div", { className: "k-field__hints", children: [error && _jsx("p", { className: cx("k-hint k-hint--error", classNames.error), id: errorId(id), children: error }), hint && _jsx("p", { className: cx("k-hint", classNames.hint), id: hintId(id), children: hint })] }), hintEnd] }))] }));
16
17
  }
@@ -14,7 +14,7 @@ export interface FileItem {
14
14
  note?: string;
15
15
  }
16
16
  /** حجم فایل: ۱٫۲ مگابایت؛ با locale="en" ← «1.2 MB» */
17
- export declare function formatBytes(bytes: number, locale?: KashiLocale): string;
17
+ export declare function formatBytes(bytes: number, locale?: KashiLocale, units?: readonly string[]): string;
18
18
  export interface ImageResizeOptions {
19
19
  /** بلندترین ضلع تصویر بعد از کوچک شدن، به پیکسل */
20
20
  maxDimension: number;