@kashi-ui/react 2.15.0 → 2.16.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 +1 -1
- package/dist/BusinessHours.d.ts +39 -0
- package/dist/BusinessHours.js +51 -0
- package/dist/Chat.d.ts +56 -0
- package/dist/Chat.js +91 -0
- package/dist/ChatComposer.d.ts +41 -0
- package/dist/ChatComposer.js +93 -0
- package/dist/CodeBlock.d.ts +23 -0
- package/dist/CodeBlock.js +84 -0
- package/dist/EconomicCodeInput.d.ts +21 -0
- package/dist/EconomicCodeInput.js +30 -0
- package/dist/Kanban.d.ts +36 -0
- package/dist/Kanban.js +218 -0
- package/dist/Lightbox.d.ts +41 -0
- package/dist/Lightbox.js +127 -0
- package/dist/NotificationCenter.d.ts +39 -0
- package/dist/NotificationCenter.js +51 -0
- package/dist/PersianInput.d.ts +6 -0
- package/dist/PersianInput.js +9 -0
- package/dist/QRCode.d.ts +24 -0
- package/dist/QRCode.js +36 -0
- package/dist/RichTextEditor.d.ts +30 -0
- package/dist/RichTextEditor.js +263 -0
- package/dist/SayadInput.d.ts +16 -0
- package/dist/SayadInput.js +24 -0
- package/dist/Scheduler.d.ts +42 -0
- package/dist/Scheduler.js +144 -0
- package/dist/Sortable.d.ts +27 -0
- package/dist/Sortable.js +137 -0
- package/dist/StreamingText.d.ts +24 -0
- package/dist/StreamingText.js +52 -0
- package/dist/TaxIdInput.d.ts +16 -0
- package/dist/TaxIdInput.js +27 -0
- package/dist/dnd.d.ts +10 -0
- package/dist/dnd.js +54 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.js +16 -0
- package/dist/qr.d.ts +7 -0
- package/dist/qr.js +271 -0
- package/package.json +4 -4
package/dist/Kanban.js
ADDED
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import { useRef, useState } from "react";
|
|
4
|
+
import { cx } from "./cx.js";
|
|
5
|
+
import { isRtl, useFlip } from "./dnd.js";
|
|
6
|
+
import { useIsomorphicLayoutEffect } from "./utils.js";
|
|
7
|
+
import { useKashi } from "./KashiProvider.js";
|
|
8
|
+
const Grip = () => (_jsx("svg", { viewBox: "0 0 20 20", fill: "currentColor", "aria-hidden": "true", children: [6, 10, 14].flatMap((y) => [_jsx("circle", { cx: "7.5", cy: y, r: "1.3" }, `a${y}`), _jsx("circle", { cx: "12.5", cy: y, r: "1.3" }, `b${y}`)]) }));
|
|
9
|
+
const Plus = () => _jsx("svg", { viewBox: "0 0 20 20", fill: "none", stroke: "currentColor", strokeWidth: 1.8, strokeLinecap: "round", "aria-hidden": "true", children: _jsx("path", { d: "M10 5v10M5 10h10" }) });
|
|
10
|
+
const tr = (el) => {
|
|
11
|
+
const [x = "0", y = "0"] = el.style.translate.split(" ");
|
|
12
|
+
return [parseFloat(x) || 0, parseFloat(y) || 0];
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* تابلوی کانبان: کارتها را بین ستونها بکشید، یا با کیبورد: فاصله برای برداشتن، بالا و پایین در ستون،
|
|
16
|
+
* چپ و راست بین ستونها (در راستبهچپ، چپ یعنی ستون بعد)، فاصله برای رها کردن و Escape برای لغو.
|
|
17
|
+
*/
|
|
18
|
+
export function Kanban({ columns, getId, getLabel, onChange, renderCard, onAdd, addLabel, "aria-label": ariaLabel, className }) {
|
|
19
|
+
const { messages: M, n } = useKashi();
|
|
20
|
+
const K = M.kanban;
|
|
21
|
+
const root = useRef(null);
|
|
22
|
+
const [preview, setPreview] = useState(null);
|
|
23
|
+
const [active, setActive] = useState(null);
|
|
24
|
+
const [mode, setMode] = useState(null);
|
|
25
|
+
const [live, setLive] = useState("");
|
|
26
|
+
const drag = useRef(null);
|
|
27
|
+
const cols = preview ?? columns;
|
|
28
|
+
useFlip(root, cols.map((c) => c.items.map(getId).join(",")).join("|"));
|
|
29
|
+
const colName = (c) => c.label ?? (typeof c.title === "string" ? c.title : c.id);
|
|
30
|
+
const find = (list, id) => {
|
|
31
|
+
for (let col = 0; col < list.length; col++) {
|
|
32
|
+
const index = list[col].items.findIndex((x) => getId(x) === id);
|
|
33
|
+
if (index >= 0)
|
|
34
|
+
return { col, index };
|
|
35
|
+
}
|
|
36
|
+
return { col: -1, index: -1 };
|
|
37
|
+
};
|
|
38
|
+
const relocate = (list, from, to) => {
|
|
39
|
+
const next = list.map((c) => ({ ...c, items: c.items.slice() }));
|
|
40
|
+
const [it] = next[from.col].items.splice(from.index, 1);
|
|
41
|
+
next[to.col].items.splice(to.index, 0, it);
|
|
42
|
+
return next;
|
|
43
|
+
};
|
|
44
|
+
const cardEl = (id) => root.current?.querySelector(`[data-flip="${CSS.escape(id)}"]`) ?? null;
|
|
45
|
+
const finish = (commit) => {
|
|
46
|
+
const id = active;
|
|
47
|
+
if (id && preview) {
|
|
48
|
+
const p = find(preview, id);
|
|
49
|
+
const item = preview[p.col]?.items[p.index];
|
|
50
|
+
if (item !== undefined) {
|
|
51
|
+
if (commit) {
|
|
52
|
+
onChange(preview);
|
|
53
|
+
setLive(K.dropped(getLabel(item), colName(preview[p.col]), n(p.index + 1)));
|
|
54
|
+
}
|
|
55
|
+
else
|
|
56
|
+
setLive(K.cancelled(getLabel(item)));
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (id) {
|
|
60
|
+
const el = cardEl(id);
|
|
61
|
+
if (el)
|
|
62
|
+
el.style.translate = "";
|
|
63
|
+
}
|
|
64
|
+
drag.current = null;
|
|
65
|
+
setPreview(null);
|
|
66
|
+
setActive(null);
|
|
67
|
+
setMode(null);
|
|
68
|
+
};
|
|
69
|
+
const finishRef = useRef(finish);
|
|
70
|
+
finishRef.current = finish;
|
|
71
|
+
// کارتی که به ستون دیگر میرود دوباره ساخته میشود و فوکوس لحظهای از دست میرود؛ در این فاصله blur لغو نکند
|
|
72
|
+
const refocusing = useRef(false);
|
|
73
|
+
// پس از هر جابهجایی کیبوردی، فوکوس همان لحظه (پیش از کلید بعدی) به دستگیرهٔ کارت برمیگردد
|
|
74
|
+
useIsomorphicLayoutEffect(() => {
|
|
75
|
+
if (mode !== "keyboard" || !active)
|
|
76
|
+
return;
|
|
77
|
+
const el = cardEl(active)?.querySelector(".k-kanban__handle");
|
|
78
|
+
if (el && document.activeElement !== el)
|
|
79
|
+
el.focus();
|
|
80
|
+
refocusing.current = false;
|
|
81
|
+
}, [preview, mode, active]);
|
|
82
|
+
const follow = (x, y) => {
|
|
83
|
+
const d = drag.current;
|
|
84
|
+
if (!d)
|
|
85
|
+
return;
|
|
86
|
+
if (!d.started) {
|
|
87
|
+
if (Math.hypot(x - d.sx, y - d.sy) < 5)
|
|
88
|
+
return;
|
|
89
|
+
d.started = true;
|
|
90
|
+
setPreview(columns);
|
|
91
|
+
setActive(d.id);
|
|
92
|
+
setMode("pointer");
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
const el = cardEl(d.id);
|
|
96
|
+
const list = preview;
|
|
97
|
+
if (!el || !list)
|
|
98
|
+
return;
|
|
99
|
+
const [tx, ty] = tr(el);
|
|
100
|
+
const r = el.getBoundingClientRect();
|
|
101
|
+
el.style.translate = `${x - d.gx - (r.left - tx)}px ${y - d.gy - (r.top - ty)}px`;
|
|
102
|
+
// ستون زیر اشارهگر
|
|
103
|
+
const colEls = Array.from(root.current.querySelectorAll(".k-kanban__col"));
|
|
104
|
+
let col = colEls.findIndex((c) => {
|
|
105
|
+
const b = c.getBoundingClientRect();
|
|
106
|
+
return x >= b.left && x <= b.right;
|
|
107
|
+
});
|
|
108
|
+
if (col < 0)
|
|
109
|
+
return;
|
|
110
|
+
const center = y - d.gy + el.offsetHeight / 2;
|
|
111
|
+
let index = 0;
|
|
112
|
+
for (const o of Array.from(colEls[col].querySelectorAll("[data-flip]"))) {
|
|
113
|
+
if (o === el)
|
|
114
|
+
continue;
|
|
115
|
+
const b = o.getBoundingClientRect();
|
|
116
|
+
if (center > b.top - tr(o)[1] + b.height / 2)
|
|
117
|
+
index++;
|
|
118
|
+
}
|
|
119
|
+
const from = find(list, d.id);
|
|
120
|
+
if (from.col !== col || from.index !== index)
|
|
121
|
+
setPreview(relocate(list, from, { col, index }));
|
|
122
|
+
};
|
|
123
|
+
const followRef = useRef(follow);
|
|
124
|
+
followRef.current = follow;
|
|
125
|
+
// رویدادها روی window گوش داده میشوند، نه روی کارت: کارتی که به ستون دیگر میرود دوباره ساخته میشود و pointer capture از دست میرود
|
|
126
|
+
const onPointerDown = (e, item) => {
|
|
127
|
+
if (e.button !== 0 || drag.current)
|
|
128
|
+
return;
|
|
129
|
+
const t = e.target;
|
|
130
|
+
if (t.closest("a, input, textarea, select, button:not(.k-kanban__handle), [contenteditable]"))
|
|
131
|
+
return;
|
|
132
|
+
const r = e.currentTarget.getBoundingClientRect();
|
|
133
|
+
const pid = e.pointerId;
|
|
134
|
+
drag.current = { id: getId(item), gx: e.clientX - r.left, gy: e.clientY - r.top, pointer: pid, sx: e.clientX, sy: e.clientY, started: false };
|
|
135
|
+
const move = (ev) => {
|
|
136
|
+
if (ev.pointerId !== pid)
|
|
137
|
+
return;
|
|
138
|
+
if (drag.current?.started)
|
|
139
|
+
ev.preventDefault();
|
|
140
|
+
followRef.current(ev.clientX, ev.clientY);
|
|
141
|
+
};
|
|
142
|
+
const stop = (ev, cancel = false) => {
|
|
143
|
+
if (ev.pointerId !== pid)
|
|
144
|
+
return;
|
|
145
|
+
window.removeEventListener("pointermove", move);
|
|
146
|
+
window.removeEventListener("pointerup", up);
|
|
147
|
+
window.removeEventListener("pointercancel", onCancel);
|
|
148
|
+
if (drag.current?.started)
|
|
149
|
+
finishRef.current(!cancel);
|
|
150
|
+
else
|
|
151
|
+
drag.current = null;
|
|
152
|
+
};
|
|
153
|
+
const up = (ev) => stop(ev);
|
|
154
|
+
const onCancel = (ev) => stop(ev, true);
|
|
155
|
+
window.addEventListener("pointermove", move, { passive: false });
|
|
156
|
+
window.addEventListener("pointerup", up);
|
|
157
|
+
window.addEventListener("pointercancel", onCancel);
|
|
158
|
+
};
|
|
159
|
+
const onKeyDown = (e, item) => {
|
|
160
|
+
const id = getId(item);
|
|
161
|
+
if (e.key === " " || e.key === "Enter") {
|
|
162
|
+
e.preventDefault();
|
|
163
|
+
if (active === id && mode === "keyboard")
|
|
164
|
+
finish(true);
|
|
165
|
+
else {
|
|
166
|
+
const p = find(columns, id);
|
|
167
|
+
setPreview(columns);
|
|
168
|
+
setActive(id);
|
|
169
|
+
setMode("keyboard");
|
|
170
|
+
setLive(K.grabbed(getLabel(item), colName(columns[p.col])));
|
|
171
|
+
}
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
if (active !== id || mode !== "keyboard" || !preview)
|
|
175
|
+
return;
|
|
176
|
+
if (e.key === "Escape") {
|
|
177
|
+
e.preventDefault();
|
|
178
|
+
finish(false);
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
const from = find(preview, id);
|
|
182
|
+
const rtl = isRtl(root.current);
|
|
183
|
+
const nextCol = rtl ? "ArrowLeft" : "ArrowRight";
|
|
184
|
+
const prevCol = rtl ? "ArrowRight" : "ArrowLeft";
|
|
185
|
+
let to = null;
|
|
186
|
+
if (e.key === "ArrowUp" && from.index > 0)
|
|
187
|
+
to = { col: from.col, index: from.index - 1 };
|
|
188
|
+
else if (e.key === "ArrowDown" && from.index < preview[from.col].items.length - 1)
|
|
189
|
+
to = { col: from.col, index: from.index + 1 };
|
|
190
|
+
else if (e.key === nextCol && from.col < preview.length - 1)
|
|
191
|
+
to = { col: from.col + 1, index: Math.min(from.index, preview[from.col + 1].items.length) };
|
|
192
|
+
else if (e.key === prevCol && from.col > 0)
|
|
193
|
+
to = { col: from.col - 1, index: Math.min(from.index, preview[from.col - 1].items.length) };
|
|
194
|
+
if (!["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"].includes(e.key))
|
|
195
|
+
return;
|
|
196
|
+
e.preventDefault();
|
|
197
|
+
if (!to)
|
|
198
|
+
return;
|
|
199
|
+
const next = relocate(preview, from, to);
|
|
200
|
+
refocusing.current = true;
|
|
201
|
+
setPreview(next);
|
|
202
|
+
setLive(K.moved(getLabel(item), colName(next[to.col]), n(to.index + 1)));
|
|
203
|
+
};
|
|
204
|
+
return (_jsxs("div", { ref: root, className: cx("k-kanban", className), role: "group", "aria-label": ariaLabel ?? K.label, "data-dragging": active ? "" : undefined, children: [cols.map((c, ci) => {
|
|
205
|
+
const over = c.limit !== undefined && c.items.length > c.limit;
|
|
206
|
+
const headId = `k-kanban-${c.id}`;
|
|
207
|
+
return (_jsxs("section", { className: "k-kanban__col", "aria-labelledby": headId, "data-over": over ? "" : undefined, "data-target": active && find(cols, active).col === ci ? "" : undefined, children: [_jsxs("header", { className: "k-kanban__head", children: [c.color && _jsx("span", { className: "k-kanban__dot", style: { background: c.color }, "aria-hidden": "true" }), _jsx("h3", { className: "k-kanban__title", id: headId, children: c.title }), _jsxs("span", { className: "k-kanban__count", "aria-label": K.count(n(c.items.length)), children: [n(c.items.length), c.limit !== undefined ? `/${n(c.limit)}` : ""] })] }), _jsxs("ul", { className: "k-kanban__list", children: [c.items.map((item) => {
|
|
208
|
+
const id = getId(item);
|
|
209
|
+
const dragging = active === id;
|
|
210
|
+
const handle = (_jsx("button", { type: "button", className: "k-kanban__handle", "aria-label": `${getLabel(item)}${M.common.list}${colName(c)}`, "aria-pressed": dragging && mode === "keyboard", "aria-describedby": `${headId}-hint`, onKeyDown: (e) => onKeyDown(e, item), onBlur: () => mode === "keyboard" && dragging &&
|
|
211
|
+
setTimeout(() => {
|
|
212
|
+
if (!refocusing.current && !root.current?.contains(document.activeElement))
|
|
213
|
+
finishRef.current(false);
|
|
214
|
+
}, 0), children: _jsx(Grip, {}) }));
|
|
215
|
+
return (_jsx("li", { className: "k-kanban__card", "data-flip": id, "data-dragging": dragging ? "" : undefined, "data-mode": dragging ? mode ?? undefined : undefined, onPointerDown: (e) => onPointerDown(e, item), children: renderCard ? renderCard(item, { handle, dragging }) : (_jsxs(_Fragment, { children: [handle, _jsx("span", { className: "k-kanban__label", children: getLabel(item) })] })) }, id));
|
|
216
|
+
}), c.items.length === 0 && _jsx("li", { className: "k-kanban__empty", children: K.empty })] }), onAdd && (_jsxs("button", { type: "button", className: "k-kanban__add", onClick: () => onAdd(c.id), children: [_jsx(Plus, {}), addLabel ?? K.add] })), _jsx("span", { id: `${headId}-hint`, hidden: true, children: K.instructions })] }, c.id));
|
|
217
|
+
}), _jsx("span", { className: "k-sr-only", "aria-live": "assertive", children: live })] }));
|
|
218
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export interface LightboxImage {
|
|
2
|
+
src: string;
|
|
3
|
+
/** متن جایگزین؛ برای صفحهخوان و برچسب دکمهٔ تصویر کوچک */
|
|
4
|
+
alt: string;
|
|
5
|
+
/** زیرنویس زیر تصویر بزرگ */
|
|
6
|
+
caption?: string;
|
|
7
|
+
/** تصویر کوچک گالری؛ بدون آن همان src */
|
|
8
|
+
thumb?: string;
|
|
9
|
+
width?: number;
|
|
10
|
+
height?: number;
|
|
11
|
+
}
|
|
12
|
+
export interface LightboxProps {
|
|
13
|
+
images: LightboxImage[];
|
|
14
|
+
/** اندیس تصویر باز؛ null یعنی بسته */
|
|
15
|
+
index: number | null;
|
|
16
|
+
onIndexChange: (index: number | null) => void;
|
|
17
|
+
/** نوار تصویرهای کوچک پایین @default true */
|
|
18
|
+
thumbnails?: boolean;
|
|
19
|
+
/** از آخر به اول برگردد @default false */
|
|
20
|
+
loop?: boolean;
|
|
21
|
+
className?: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* نمایش تمامصفحهٔ تصویر روی <dialog> بومی: فلشها (در راستبهچپ، چپ یعنی بعدی)، Home و End، کشیدن انگشت،
|
|
25
|
+
* بزرگنمایی با کلیک یا دوبار ضربه، و برگشت فوکوس به تصویر کوچک پس از بستن.
|
|
26
|
+
*/
|
|
27
|
+
export declare function Lightbox({ images, index, onIndexChange, thumbnails, loop, className }: LightboxProps): import("react").JSX.Element;
|
|
28
|
+
export interface GalleryProps {
|
|
29
|
+
images: LightboxImage[];
|
|
30
|
+
/** تعداد ستون؛ بدون آن خودکار بر اساس عرض */
|
|
31
|
+
columns?: number;
|
|
32
|
+
/** نسبت تصویرهای کوچک @default "1 / 1" */
|
|
33
|
+
aspect?: string;
|
|
34
|
+
/** ستونهای بیشتر از این تعداد با «+n» جمع میشوند */
|
|
35
|
+
max?: number;
|
|
36
|
+
loop?: boolean;
|
|
37
|
+
"aria-label"?: string;
|
|
38
|
+
className?: string;
|
|
39
|
+
}
|
|
40
|
+
/** شبکهٔ تصویرهای کوچک که هر کدام با کلیک در نمایش تمامصفحه باز میشود */
|
|
41
|
+
export declare function Gallery({ images, columns, aspect, max, loop, "aria-label": ariaLabel, className }: GalleryProps): import("react").JSX.Element;
|
package/dist/Lightbox.js
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect, useId, useRef, useState } from "react";
|
|
4
|
+
import { cx } from "./cx.js";
|
|
5
|
+
import { isRtl } from "./dnd.js";
|
|
6
|
+
import { useKashi } from "./KashiProvider.js";
|
|
7
|
+
import { useModalDialog } from "./modal.js";
|
|
8
|
+
const svg = (d, w = 1.8) => (_jsx("svg", { viewBox: "0 0 20 20", fill: "none", stroke: "currentColor", strokeWidth: w, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: _jsx("path", { d: d }) }));
|
|
9
|
+
/**
|
|
10
|
+
* نمایش تمامصفحهٔ تصویر روی <dialog> بومی: فلشها (در راستبهچپ، چپ یعنی بعدی)، Home و End، کشیدن انگشت،
|
|
11
|
+
* بزرگنمایی با کلیک یا دوبار ضربه، و برگشت فوکوس به تصویر کوچک پس از بستن.
|
|
12
|
+
*/
|
|
13
|
+
export function Lightbox({ images, index, onIndexChange, thumbnails = true, loop = false, className }) {
|
|
14
|
+
const { messages: M, n } = useKashi();
|
|
15
|
+
const L = M.lightbox;
|
|
16
|
+
const ref = useRef(null);
|
|
17
|
+
const open = index !== null;
|
|
18
|
+
const { restoreFocus } = useModalDialog(ref, open);
|
|
19
|
+
const [zoom, setZoom] = useState(null);
|
|
20
|
+
const [dir, setDir] = useState(1);
|
|
21
|
+
const swipe = useRef(null);
|
|
22
|
+
const [dx, setDx] = useState(0);
|
|
23
|
+
const titleId = useId();
|
|
24
|
+
const last = useRef(0);
|
|
25
|
+
if (index !== null)
|
|
26
|
+
last.current = index;
|
|
27
|
+
const i = index ?? last.current;
|
|
28
|
+
const img = images[i];
|
|
29
|
+
const count = images.length;
|
|
30
|
+
const go = (to) => {
|
|
31
|
+
if (!count)
|
|
32
|
+
return;
|
|
33
|
+
const next = loop ? (to + count) % count : Math.max(0, Math.min(count - 1, to));
|
|
34
|
+
if (next === i)
|
|
35
|
+
return;
|
|
36
|
+
setDir(next > i ? 1 : -1);
|
|
37
|
+
setZoom(null);
|
|
38
|
+
onIndexChange(next);
|
|
39
|
+
};
|
|
40
|
+
// پیشبارگذاری تصویرهای کناری
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
if (!open)
|
|
43
|
+
return;
|
|
44
|
+
for (const j of [i - 1, i + 1]) {
|
|
45
|
+
const s = images[(j + count) % count]?.src;
|
|
46
|
+
if (s && typeof Image === "function")
|
|
47
|
+
new Image().src = s;
|
|
48
|
+
}
|
|
49
|
+
}, [open, i, images, count]);
|
|
50
|
+
useEffect(() => {
|
|
51
|
+
if (!open)
|
|
52
|
+
setZoom(null);
|
|
53
|
+
}, [open]);
|
|
54
|
+
// تصویر کوچک فعلی در نوار دیده شود
|
|
55
|
+
useEffect(() => {
|
|
56
|
+
if (!open)
|
|
57
|
+
return;
|
|
58
|
+
ref.current?.querySelector(`[data-thumb="${i}"]`)?.scrollIntoView?.({ block: "nearest", inline: "center" });
|
|
59
|
+
}, [open, i]);
|
|
60
|
+
const onKey = (e) => {
|
|
61
|
+
const rtl = isRtl(ref.current);
|
|
62
|
+
if (e.key === "ArrowRight")
|
|
63
|
+
go(i + (rtl ? -1 : 1));
|
|
64
|
+
else if (e.key === "ArrowLeft")
|
|
65
|
+
go(i + (rtl ? 1 : -1));
|
|
66
|
+
else if (e.key === "Home")
|
|
67
|
+
go(0);
|
|
68
|
+
else if (e.key === "End")
|
|
69
|
+
go(count - 1);
|
|
70
|
+
else
|
|
71
|
+
return;
|
|
72
|
+
e.preventDefault();
|
|
73
|
+
};
|
|
74
|
+
const canPrev = loop || i > 0;
|
|
75
|
+
const canNext = loop || i < count - 1;
|
|
76
|
+
return (_jsxs("dialog", { ref: ref, className: cx("k-lightbox", className), "aria-labelledby": titleId, onKeyDown: onKey, onClose: () => {
|
|
77
|
+
if (open)
|
|
78
|
+
onIndexChange(null);
|
|
79
|
+
restoreFocus();
|
|
80
|
+
}, onCancel: (e) => {
|
|
81
|
+
e.preventDefault();
|
|
82
|
+
if (zoom)
|
|
83
|
+
setZoom(null);
|
|
84
|
+
else
|
|
85
|
+
onIndexChange(null);
|
|
86
|
+
}, onClick: (e) => {
|
|
87
|
+
if (e.target === e.currentTarget || e.target.classList.contains("k-lightbox__stage"))
|
|
88
|
+
onIndexChange(null);
|
|
89
|
+
}, children: [_jsx("h2", { className: "k-sr-only", id: titleId, children: L.label }), _jsxs("div", { className: "k-lightbox__bar", children: [_jsx("span", { className: "k-lightbox__counter", "aria-live": "polite", children: L.counter(n(i + 1), n(count)) }), _jsx("button", { type: "button", className: "k-lightbox__btn", "aria-label": zoom ? L.zoomOut : L.zoomIn, "aria-pressed": !!zoom, onClick: () => setZoom(zoom ? null : { x: 50, y: 50 }), children: zoom ? svg("M8.5 14a5.5 5.5 0 1 0 0-11 5.5 5.5 0 0 0 0 11ZM17 17l-4.2-4.2M6 8.5h5") : svg("M8.5 14a5.5 5.5 0 1 0 0-11 5.5 5.5 0 0 0 0 11ZM17 17l-4.2-4.2M6 8.5h5M8.5 6v5") }), _jsx("button", { type: "button", className: "k-lightbox__btn", "aria-label": L.close, onClick: () => onIndexChange(null), autoFocus: true, children: svg("M5 5l10 10M15 5 5 15") })] }), _jsxs("div", { className: "k-lightbox__stage", onPointerDown: (e) => {
|
|
90
|
+
if (zoom || e.target.closest("button"))
|
|
91
|
+
return;
|
|
92
|
+
swipe.current = { x: e.clientX, y: e.clientY, id: e.pointerId };
|
|
93
|
+
}, onPointerMove: (e) => swipe.current?.id === e.pointerId && setDx(e.clientX - swipe.current.x), onPointerUp: (e) => {
|
|
94
|
+
const s = swipe.current;
|
|
95
|
+
swipe.current = null;
|
|
96
|
+
setDx(0);
|
|
97
|
+
if (!s || s.id !== e.pointerId)
|
|
98
|
+
return;
|
|
99
|
+
const d = e.clientX - s.x;
|
|
100
|
+
if (Math.abs(d) > 60 && Math.abs(d) > Math.abs(e.clientY - s.y)) {
|
|
101
|
+
// کشیدن به سمت شروع خط یعنی بعدی
|
|
102
|
+
const rtl = isRtl(ref.current);
|
|
103
|
+
go(i + ((d < 0) !== rtl ? 1 : -1));
|
|
104
|
+
}
|
|
105
|
+
}, onPointerCancel: () => {
|
|
106
|
+
swipe.current = null;
|
|
107
|
+
setDx(0);
|
|
108
|
+
}, children: [img && (_jsxs("figure", { className: "k-lightbox__figure", "data-dir": dir > 0 ? "next" : "prev", style: dx ? { translate: `${dx}px 0`, transition: "none" } : undefined, children: [_jsx("img", { className: "k-lightbox__img", src: img.src, alt: img.alt, width: img.width, height: img.height, draggable: false, "data-zoom": zoom ? "" : undefined, style: zoom ? { transformOrigin: `${zoom.x}% ${zoom.y}%` } : undefined, onClick: (e) => {
|
|
109
|
+
if (Math.abs(dx) > 4)
|
|
110
|
+
return;
|
|
111
|
+
const r = e.currentTarget.getBoundingClientRect();
|
|
112
|
+
setZoom(zoom ? null : { x: ((e.clientX - r.left) / r.width) * 100, y: ((e.clientY - r.top) / r.height) * 100 });
|
|
113
|
+
}, onPointerMove: (e) => {
|
|
114
|
+
if (!zoom || e.pointerType === "touch")
|
|
115
|
+
return;
|
|
116
|
+
const r = e.currentTarget.getBoundingClientRect();
|
|
117
|
+
setZoom({ x: ((e.clientX - r.left) / r.width) * 100, y: ((e.clientY - r.top) / r.height) * 100 });
|
|
118
|
+
} }), img.caption && _jsx("figcaption", { className: "k-lightbox__caption", dir: "auto", children: img.caption })] }, i)), count > 1 && (_jsxs(_Fragment, { children: [_jsx("button", { type: "button", className: "k-lightbox__nav k-lightbox__nav--prev", "aria-label": L.prev, disabled: !canPrev, onClick: () => go(i - 1), children: svg("m8 5 5 5-5 5") }), _jsx("button", { type: "button", className: "k-lightbox__nav k-lightbox__nav--next", "aria-label": L.next, disabled: !canNext, onClick: () => go(i + 1), children: svg("m12 5-5 5 5 5") })] }))] }), thumbnails && count > 1 && (_jsx("div", { className: "k-lightbox__thumbs", children: images.map((t, j) => (_jsx("button", { type: "button", className: "k-lightbox__thumb", "data-thumb": j, "aria-label": t.alt, "aria-current": j === i ? "true" : undefined, onClick: () => go(j), children: _jsx("img", { src: t.thumb ?? t.src, alt: "", loading: "lazy", draggable: false }) }, j))) }))] }));
|
|
119
|
+
}
|
|
120
|
+
/** شبکهٔ تصویرهای کوچک که هر کدام با کلیک در نمایش تمامصفحه باز میشود */
|
|
121
|
+
export function Gallery({ images, columns, aspect = "1 / 1", max, loop, "aria-label": ariaLabel, className }) {
|
|
122
|
+
const { messages: M, n } = useKashi();
|
|
123
|
+
const [open, setOpen] = useState(null);
|
|
124
|
+
const shown = max && images.length > max ? images.slice(0, max) : images;
|
|
125
|
+
const rest = images.length - shown.length;
|
|
126
|
+
return (_jsxs(_Fragment, { children: [_jsx("ul", { className: cx("k-gallery", className), "aria-label": ariaLabel ?? M.lightbox.gallery, style: { ...(columns ? { "--k-gallery-cols": columns } : {}), "--k-gallery-aspect": aspect }, children: shown.map((img, j) => (_jsx("li", { children: _jsxs("button", { type: "button", className: "k-gallery__item", "aria-label": rest > 0 && j === shown.length - 1 ? `${M.lightbox.open(img.alt)} +${n(rest)}` : M.lightbox.open(img.alt), onClick: () => setOpen(j), children: [_jsx("img", { src: img.thumb ?? img.src, alt: "", loading: "lazy", width: img.width, height: img.height }), rest > 0 && j === shown.length - 1 && _jsxs("span", { className: "k-gallery__more", "aria-hidden": "true", children: ["+", n(rest)] })] }) }, j))) }), _jsx(Lightbox, { images: images, index: open, onIndexChange: setOpen, loop: loop })] }));
|
|
127
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
export interface NotificationItem {
|
|
3
|
+
id: string;
|
|
4
|
+
title: ReactNode;
|
|
5
|
+
body?: ReactNode;
|
|
6
|
+
time: Date;
|
|
7
|
+
read?: boolean;
|
|
8
|
+
/** آواتار یا آیکون سمت شروع */
|
|
9
|
+
icon?: ReactNode;
|
|
10
|
+
tone?: "brand" | "success" | "warning" | "error";
|
|
11
|
+
/** پیوند اعلان؛ بدون آن onSelect صدا زده میشود */
|
|
12
|
+
href?: string;
|
|
13
|
+
}
|
|
14
|
+
export interface NotificationListProps {
|
|
15
|
+
items: NotificationItem[];
|
|
16
|
+
/** خوانده شدن یک اعلان (با کلیک یا دکمهٔ نقطه) */
|
|
17
|
+
onRead?: (id: string) => void;
|
|
18
|
+
onReadAll?: () => void;
|
|
19
|
+
onSelect?: (item: NotificationItem) => void;
|
|
20
|
+
/** دکمهٔ تنظیمات کنار عنوان */
|
|
21
|
+
onSettings?: () => void;
|
|
22
|
+
/** پیوند «دیدن همهٔ اعلانها» پایین فهرست */
|
|
23
|
+
viewAllHref?: string;
|
|
24
|
+
/** عنوان بالای فهرست @default "اعلانها" */
|
|
25
|
+
title?: ReactNode;
|
|
26
|
+
/** لحظهٔ مقایسه برای زمان نسبی و گروه امروز و دیروز @default اکنون */
|
|
27
|
+
now?: Date;
|
|
28
|
+
className?: string;
|
|
29
|
+
}
|
|
30
|
+
/** فهرست اعلانها با زبانههای «همه» و «خواندهنشده»، گروه امروز و دیروز و زمان نسبی فارسی؛ تنها یا داخل NotificationCenter */
|
|
31
|
+
export declare function NotificationList({ items, onRead, onReadAll, onSelect, onSettings, viewAllHref, title, now, className }: NotificationListProps): import("react").JSX.Element;
|
|
32
|
+
export interface NotificationCenterProps extends NotificationListProps {
|
|
33
|
+
open?: boolean;
|
|
34
|
+
onOpenChange?: (open: boolean) => void;
|
|
35
|
+
/** @default "bottom-end" */
|
|
36
|
+
placement?: "bottom-start" | "bottom-end";
|
|
37
|
+
}
|
|
38
|
+
/** دکمهٔ زنگ با شمار اعلانهای خواندهنشده که فهرست اعلانها را در پاپاور باز میکند */
|
|
39
|
+
export declare function NotificationCenter({ open, onOpenChange, placement, className, ...list }: NotificationCenterProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect, useRef, useState } from "react";
|
|
4
|
+
import { formatRelative } from "@kashi-ui/persian";
|
|
5
|
+
import { cx } from "./cx.js";
|
|
6
|
+
import { useKashi } from "./KashiProvider.js";
|
|
7
|
+
import { Popover } from "./Popover.js";
|
|
8
|
+
const svg = (d) => _jsx("svg", { viewBox: "0 0 20 20", fill: "none", stroke: "currentColor", strokeWidth: 1.7, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: _jsx("path", { d: d }) });
|
|
9
|
+
const Bell = () => svg("M5 8a5 5 0 0 1 10 0c0 4 1.5 5.5 1.5 5.5h-13S5 12 5 8ZM8.5 16.5a1.6 1.6 0 0 0 3 0");
|
|
10
|
+
const Gear = () => svg("M10 12.5a2.5 2.5 0 1 0 0-5 2.5 2.5 0 0 0 0 5ZM16 10a6 6 0 0 0-.1-1l1.6-1.3-1.5-2.6-2 .7a6 6 0 0 0-1.7-1L12 2.8H9l-.4 2a6 6 0 0 0-1.7 1l-2-.7-1.5 2.6L5 9a6 6 0 0 0 0 2l-1.6 1.3 1.5 2.6 2-.7a6 6 0 0 0 1.7 1l.4 2h3l.4-2a6 6 0 0 0 1.7-1l2 .7 1.5-2.6L15.9 11c.1-.3.1-.7.1-1Z");
|
|
11
|
+
const CheckAll = () => svg("m2.5 10.5 3 3 6-7M9 13.2l.3.3 6-7");
|
|
12
|
+
const day = (d) => new Date(d.getFullYear(), d.getMonth(), d.getDate()).getTime();
|
|
13
|
+
/** فهرست اعلانها با زبانههای «همه» و «خواندهنشده»، گروه امروز و دیروز و زمان نسبی فارسی؛ تنها یا داخل NotificationCenter */
|
|
14
|
+
export function NotificationList({ items, onRead, onReadAll, onSelect, onSettings, viewAllHref, title, now, className }) {
|
|
15
|
+
const { messages: M, locale, digits, n } = useKashi();
|
|
16
|
+
const N = M.notifications;
|
|
17
|
+
const [tab, setTab] = useState("all");
|
|
18
|
+
const unread = items.filter((x) => !x.read).length;
|
|
19
|
+
const list = tab === "unread" ? items.filter((x) => !x.read) : items;
|
|
20
|
+
const ref = now ?? new Date();
|
|
21
|
+
const today = day(ref);
|
|
22
|
+
const groups = [[N.today, []], [N.yesterday, []], [N.earlier, []]];
|
|
23
|
+
for (const it of [...list].sort((a, b) => b.time.getTime() - a.time.getTime())) {
|
|
24
|
+
const d = day(it.time);
|
|
25
|
+
groups[d >= today ? 0 : d >= today - 86400000 ? 1 : 2][1].push(it);
|
|
26
|
+
}
|
|
27
|
+
return (_jsxs("div", { className: cx("k-notif", className), children: [_jsxs("div", { className: "k-notif__head", children: [_jsx("h2", { className: "k-notif__title", children: title ?? N.label }), onReadAll && unread > 0 && (_jsxs("button", { type: "button", className: "k-notif__link", onClick: onReadAll, children: [_jsx(CheckAll, {}), N.markAll] })), onSettings && _jsx("button", { type: "button", className: "k-notif__icon", "aria-label": N.settings, onClick: onSettings, children: _jsx(Gear, {}) })] }), _jsx("div", { className: "k-notif__tabs", role: "group", children: ["all", "unread"].map((t) => (_jsxs("button", { type: "button", className: "k-notif__tab", "aria-pressed": tab === t, onClick: () => setTab(t), children: [N[t], t === "unread" && unread > 0 && _jsx("span", { className: "k-notif__count", children: n(unread) })] }, t))) }), list.length === 0 ? (_jsxs("div", { className: "k-notif__empty", children: [_jsx("span", { className: "k-notif__empty-icon", children: _jsx(Bell, {}) }), _jsx("p", { children: tab === "unread" ? N.emptyUnread : N.empty })] })) : (_jsx("div", { className: "k-notif__scroll", tabIndex: -1, children: groups.filter(([, g]) => g.length).map(([name, g]) => (_jsxs("section", { className: "k-notif__group", "aria-label": name, children: [_jsx("h3", { className: "k-notif__group-title", children: name }), _jsx("ul", { className: "k-notif__list", children: g.map((it) => {
|
|
28
|
+
const inner = (_jsxs(_Fragment, { children: [it.icon && _jsx("span", { className: "k-notif__media", "data-tone": it.tone, children: it.icon }), _jsxs("span", { className: "k-notif__text", children: [_jsx("span", { className: "k-notif__item-title", children: it.title }), it.body && _jsx("span", { className: "k-notif__body", children: it.body }), _jsx("time", { className: "k-notif__time", dateTime: it.time.toISOString(), children: formatRelative(it.time, { now: ref, locale, digits }) })] })] }));
|
|
29
|
+
const select = () => {
|
|
30
|
+
if (!it.read)
|
|
31
|
+
onRead?.(it.id);
|
|
32
|
+
onSelect?.(it);
|
|
33
|
+
};
|
|
34
|
+
return (_jsxs("li", { className: "k-notif__item", "data-unread": it.read ? undefined : "", children: [it.href ? (_jsx("a", { className: "k-notif__main", href: it.href, onClick: select, children: inner })) : (_jsx("button", { type: "button", className: "k-notif__main", onClick: select, children: inner })), !it.read && (_jsx("button", { type: "button", className: "k-notif__dot", "aria-label": N.markRead, title: N.markRead, onClick: () => onRead?.(it.id), children: _jsx("span", { "aria-hidden": "true" }) }))] }, it.id));
|
|
35
|
+
}) })] }, name))) })), viewAllHref && _jsx("a", { className: "k-notif__all", href: viewAllHref, children: N.viewAll })] }));
|
|
36
|
+
}
|
|
37
|
+
/** دکمهٔ زنگ با شمار اعلانهای خواندهنشده که فهرست اعلانها را در پاپاور باز میکند */
|
|
38
|
+
export function NotificationCenter({ open, onOpenChange, placement = "bottom-end", className, ...list }) {
|
|
39
|
+
const { messages: M, n } = useKashi();
|
|
40
|
+
const N = M.notifications;
|
|
41
|
+
const unread = list.items.filter((x) => !x.read).length;
|
|
42
|
+
// با رسیدن اعلان تازه، شمارنده یک بار تکان میخورد
|
|
43
|
+
const prev = useRef(unread);
|
|
44
|
+
const [bump, setBump] = useState(0);
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
if (unread > prev.current)
|
|
47
|
+
setBump((b) => b + 1);
|
|
48
|
+
prev.current = unread;
|
|
49
|
+
}, [unread]);
|
|
50
|
+
return (_jsx(Popover, { open: open, onOpenChange: onOpenChange, placement: placement, "aria-label": N.label, className: cx("k-notif-pop", className), trigger: _jsxs("button", { type: "button", className: "k-btn k-btn--tertiary k-btn--icon k-notif__bell", "aria-label": unread ? N.button(n(unread)) : N.label, children: [_jsx(Bell, {}), unread > 0 && _jsx("span", { className: "k-notif__badge", "aria-hidden": "true", children: unread > 99 ? `${n(99)}+` : n(unread) }, bump)] }), children: _jsx(NotificationList, { ...list }) }));
|
|
51
|
+
}
|
package/dist/PersianInput.d.ts
CHANGED
|
@@ -7,6 +7,9 @@ import { type MobileInputProps } from "./MobileInput.js";
|
|
|
7
7
|
import { type NationalIdInputProps } from "./NationalIdInput.js";
|
|
8
8
|
import { type PostalCodeInputProps } from "./PostalCodeInput.js";
|
|
9
9
|
import { type PlateInputProps } from "./PlateInput.js";
|
|
10
|
+
import { type SayadInputProps } from "./SayadInput.js";
|
|
11
|
+
import { type EconomicCodeInputProps } from "./EconomicCodeInput.js";
|
|
12
|
+
import { type TaxIdInputProps } from "./TaxIdInput.js";
|
|
10
13
|
import { type PriceInputProps } from "./PriceInput.js";
|
|
11
14
|
import { type TimeInputProps } from "./TimeInput.js";
|
|
12
15
|
/** نوعهای پشتیبانیشده و ویژگیهای هر کدام؛ همان ویژگیهای کامپوننت تخصصی */
|
|
@@ -22,6 +25,9 @@ export interface PersianInputKinds {
|
|
|
22
25
|
postal: PostalCodeInputProps;
|
|
23
26
|
time: TimeInputProps;
|
|
24
27
|
plate: PlateInputProps;
|
|
28
|
+
sayad: SayadInputProps;
|
|
29
|
+
"economic-code": EconomicCodeInputProps;
|
|
30
|
+
"tax-id": TaxIdInputProps;
|
|
25
31
|
}
|
|
26
32
|
export type PersianInputKind = keyof PersianInputKinds;
|
|
27
33
|
export type PersianInputProps = {
|
package/dist/PersianInput.js
CHANGED
|
@@ -10,6 +10,9 @@ import { MobileInput } from "./MobileInput.js";
|
|
|
10
10
|
import { NationalIdInput } from "./NationalIdInput.js";
|
|
11
11
|
import { PostalCodeInput } from "./PostalCodeInput.js";
|
|
12
12
|
import { PlateInput } from "./PlateInput.js";
|
|
13
|
+
import { SayadInput } from "./SayadInput.js";
|
|
14
|
+
import { EconomicCodeInput } from "./EconomicCodeInput.js";
|
|
15
|
+
import { TaxIdInput } from "./TaxIdInput.js";
|
|
13
16
|
import { PriceInput } from "./PriceInput.js";
|
|
14
17
|
import { TimeInput } from "./TimeInput.js";
|
|
15
18
|
import { useKashi } from "./KashiProvider.js";
|
|
@@ -26,6 +29,9 @@ export const PERSIAN_INPUT_LABELS = {
|
|
|
26
29
|
postal: "کد پستی",
|
|
27
30
|
time: "ساعت",
|
|
28
31
|
plate: "پلاک خودرو",
|
|
32
|
+
sayad: "شناسهٔ صیادی چک",
|
|
33
|
+
"economic-code": "کد اقتصادی",
|
|
34
|
+
"tax-id": "شمارهٔ مالیاتی فاکتور",
|
|
29
35
|
};
|
|
30
36
|
const COMPONENTS = {
|
|
31
37
|
text: KeyboardFixInput,
|
|
@@ -39,6 +45,9 @@ const COMPONENTS = {
|
|
|
39
45
|
postal: PostalCodeInput,
|
|
40
46
|
time: TimeInput,
|
|
41
47
|
plate: PlateInput,
|
|
48
|
+
sayad: SayadInput,
|
|
49
|
+
"economic-code": EconomicCodeInput,
|
|
50
|
+
"tax-id": TaxIdInput,
|
|
42
51
|
};
|
|
43
52
|
/**
|
|
44
53
|
* یک فیلد برای همهٔ دادههای فارسی (کد ملی، شبا، کارت، مبلغ، کد پستی، ساعت، پلاک و…): نوع را با kind انتخاب کنید و بقیهٔ ویژگیها همان کامپوننت تخصصی است.
|
package/dist/QRCode.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import { type QrLevel } from "./qr.js";
|
|
3
|
+
export interface QRCodeProps {
|
|
4
|
+
/** متن یا نشانی؛ فارسی هم با UTF-8 پشتیبانی میشود */
|
|
5
|
+
value: string;
|
|
6
|
+
/** اندازه به پیکسل @default 160 */
|
|
7
|
+
size?: number;
|
|
8
|
+
/** سطح تصحیح خطا؛ با logo همیشه H @default "M" */
|
|
9
|
+
level?: QrLevel;
|
|
10
|
+
/** حاشیهٔ خالی دور کد به تعداد خانه (استاندارد ۴) @default 4 */
|
|
11
|
+
margin?: number;
|
|
12
|
+
/** لوگو یا آیکون وسط کد */
|
|
13
|
+
logo?: ReactNode;
|
|
14
|
+
/** گوشههای گرد خانهها و نشانگرها @default true */
|
|
15
|
+
rounded?: boolean;
|
|
16
|
+
/** نام دسترسپذیر؛ بدون آن «کد QR برای …» */
|
|
17
|
+
"aria-label"?: string;
|
|
18
|
+
className?: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* کد QR بدون کتابخانهٔ جانبی، به شکل SVG: رنگ از currentColor و پسزمینه از --k-qr-bg میآید.
|
|
22
|
+
* کد همیشه تیره روی روشن است تا همهٔ دوربینها بخوانندش، حتی در تم تیره.
|
|
23
|
+
*/
|
|
24
|
+
export declare function QRCode({ value, size, level, margin, logo, rounded, "aria-label": ariaLabel, className }: QRCodeProps): import("react").JSX.Element;
|
package/dist/QRCode.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useMemo } from "react";
|
|
4
|
+
import { cx } from "./cx.js";
|
|
5
|
+
import { useKashi } from "./KashiProvider.js";
|
|
6
|
+
import { encodeQr } from "./qr.js";
|
|
7
|
+
/**
|
|
8
|
+
* کد QR بدون کتابخانهٔ جانبی، به شکل SVG: رنگ از currentColor و پسزمینه از --k-qr-bg میآید.
|
|
9
|
+
* کد همیشه تیره روی روشن است تا همهٔ دوربینها بخوانندش، حتی در تم تیره.
|
|
10
|
+
*/
|
|
11
|
+
export function QRCode({ value, size = 160, level = "M", margin = 4, logo, rounded = true, "aria-label": ariaLabel, className }) {
|
|
12
|
+
const { messages: M } = useKashi();
|
|
13
|
+
const lvl = logo ? "H" : level;
|
|
14
|
+
const matrix = useMemo(() => encodeQr(value, lvl), [value, lvl]);
|
|
15
|
+
if (!matrix)
|
|
16
|
+
return _jsx("p", { className: "k-hint k-hint--error", children: M.qr.tooLong });
|
|
17
|
+
const n = matrix.length;
|
|
18
|
+
const full = n + margin * 2;
|
|
19
|
+
// خانههای نشانگر جدا کشیده میشوند تا گرد شوند
|
|
20
|
+
const inFinder = (x, y) => (x < 7 && y < 7) || (x >= n - 7 && y < 7) || (x < 7 && y >= n - 7);
|
|
21
|
+
// جای لوگو خالی میماند (حدود ۲۰٪ عرض؛ سطح H تا ۳۰٪ آسیب را جبران میکند)
|
|
22
|
+
const hole = logo ? Math.ceil(n * 0.22) | 1 : 0;
|
|
23
|
+
const h0 = (n - hole) / 2;
|
|
24
|
+
const inHole = (x, y) => hole > 0 && x >= h0 - 0.5 && x < h0 + hole - 0.5 && y >= h0 - 0.5 && y < h0 + hole - 0.5;
|
|
25
|
+
let d = "";
|
|
26
|
+
for (let y = 0; y < n; y++)
|
|
27
|
+
for (let x = 0; x < n; x++)
|
|
28
|
+
if (matrix[y][x] && !inFinder(x, y) && !inHole(x, y))
|
|
29
|
+
d += `M${x + margin} ${y + margin}h1v1h-1z`;
|
|
30
|
+
const r = rounded ? 1 : 0;
|
|
31
|
+
const finder = (fx, fy) => {
|
|
32
|
+
const x = fx + margin, y = fy + margin;
|
|
33
|
+
return (_jsxs("g", { children: [_jsx("path", { fillRule: "evenodd", d: `M${x + r * 1.6} ${y}h${7 - r * 3.2}a${r * 1.6} ${r * 1.6} 0 0 1 ${r * 1.6} ${r * 1.6}v${7 - r * 3.2}a${r * 1.6} ${r * 1.6} 0 0 1 -${r * 1.6} ${r * 1.6}h-${7 - r * 3.2}a${r * 1.6} ${r * 1.6} 0 0 1 -${r * 1.6} -${r * 1.6}v-${7 - r * 3.2}a${r * 1.6} ${r * 1.6} 0 0 1 ${r * 1.6} -${r * 1.6}zM${x + 1} ${y + 1}v5h5v-5z` }), _jsx("rect", { x: x + 2, y: y + 2, width: 3, height: 3, rx: r * 0.8 })] }, `${fx}-${fy}`));
|
|
34
|
+
};
|
|
35
|
+
return (_jsxs("span", { className: cx("k-qr", className), style: { inlineSize: size, blockSize: size }, children: [_jsxs("svg", { viewBox: `0 0 ${full} ${full}`, width: size, height: size, role: "img", "aria-label": ariaLabel ?? M.qr.label(value), shapeRendering: rounded ? undefined : "crispEdges", children: [_jsx("rect", { width: full, height: full, className: "k-qr__bg", rx: rounded ? 2 : 0 }), _jsxs("g", { className: "k-qr__fg", children: [_jsx("path", { d: d }), finder(0, 0), finder(n - 7, 0), finder(0, n - 7)] })] }), logo && _jsx("span", { className: "k-qr__logo", style: { inlineSize: `${(hole / full) * 100 * 0.9}%` }, children: logo })] }));
|
|
36
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
export type RichTextTool = "bold" | "italic" | "underline" | "strike" | "heading" | "quote" | "bullet" | "ordered" | "link" | "direction" | "undo" | "clear" | "|";
|
|
3
|
+
export interface RichTextEditorProps {
|
|
4
|
+
/** HTML کنترلشده؛ پیش از نمایش پاکسازی میشود */
|
|
5
|
+
value?: string;
|
|
6
|
+
defaultValue?: string;
|
|
7
|
+
/** با هر تغییر: HTML پاکشده و متن ساده */
|
|
8
|
+
onChange?: (html: string, text: string) => void;
|
|
9
|
+
/** @default "ویرایشگر متن" */
|
|
10
|
+
label?: string;
|
|
11
|
+
/** نام دسترسپذیر وقتی برچسب دیداری ندارد */
|
|
12
|
+
"aria-label"?: string;
|
|
13
|
+
placeholder?: string;
|
|
14
|
+
/** ابزارهای نوار و ترتیبشان؛ "|" جداکننده است */
|
|
15
|
+
tools?: RichTextTool[];
|
|
16
|
+
/** کمترین ارتفاع ناحیهٔ نوشتن @default "8rem" */
|
|
17
|
+
minHeight?: string;
|
|
18
|
+
/** شمارش کلمه و نویسه پایین ویرایشگر @default true */
|
|
19
|
+
showCount?: boolean;
|
|
20
|
+
/** با name، HTML در فرم ارسال میشود */
|
|
21
|
+
name?: string;
|
|
22
|
+
hint?: ReactNode;
|
|
23
|
+
error?: ReactNode;
|
|
24
|
+
disabled?: boolean;
|
|
25
|
+
className?: string;
|
|
26
|
+
}
|
|
27
|
+
/** پاکسازی HTML: فقط برچسبهای متنی مجاز، پیوندهای http، https و mailto، و ویژگی dir؛ بقیه حذف میشود */
|
|
28
|
+
export declare function sanitizeRichText(html: string): string;
|
|
29
|
+
/** ویرایشگر متن غنی سبک و فارسی: جهت هر بند جدا، نیمفاصله با Shift+Space، چسباندن پاکشده و نوار ابزار با کیبورد */
|
|
30
|
+
export declare function RichTextEditor({ value, defaultValue, onChange, label, "aria-label": ariaLabel, placeholder, tools, minHeight, showCount, name, hint, error, disabled, className, }: RichTextEditorProps): import("react").JSX.Element;
|