@kashi-ui/elements 0.0.0-stage → 0.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.
Files changed (61) hide show
  1. package/README.md +45 -2
  2. package/dist/base.d.ts +47 -0
  3. package/dist/base.js +148 -0
  4. package/dist/calendar.d.ts +86 -0
  5. package/dist/calendar.js +439 -0
  6. package/dist/cdn/base-Cmq7zeIG.js +1 -0
  7. package/dist/cdn/calendar-Dm3fq2bs.js +16 -0
  8. package/dist/cdn/charts-DNOWi4sJ.js +1 -0
  9. package/dist/cdn/combobox-ZGrZ5okg.js +1 -0
  10. package/dist/cdn/controls-K-OZcjg4.js +1 -0
  11. package/dist/cdn/digits-DE1YGT94.js +1 -0
  12. package/dist/cdn/display-C975tS7j.js +1 -0
  13. package/dist/cdn/dist-D670Gw0K.js +1 -0
  14. package/dist/cdn/fields-BUTaSN8m.js +1 -0
  15. package/dist/cdn/forms-C-effPKn.js +1 -0
  16. package/dist/cdn/inputs-BjOddAM7.js +1 -0
  17. package/dist/cdn/jalali-BiM5Kfep.js +1 -0
  18. package/dist/cdn/kashi-elements.js +1 -0
  19. package/dist/cdn/map-BHuusa4t.js +12 -0
  20. package/dist/cdn/menu-DhrqyLgy.js +1 -0
  21. package/dist/cdn/nav-D_w5BV_K.js +1 -0
  22. package/dist/cdn/overlay-DX9un2xm.js +1 -0
  23. package/dist/cdn/pickers-BFLpUruK.js +1 -0
  24. package/dist/cdn/table-DPQfDMs-.js +1 -0
  25. package/dist/cdn/text-D1U32D6K.js +1 -0
  26. package/dist/cdn/words-9OdzG7y6.js +1 -0
  27. package/dist/cdn.d.ts +3 -0
  28. package/dist/cdn.js +44 -0
  29. package/dist/charts.d.ts +106 -0
  30. package/dist/charts.js +436 -0
  31. package/dist/combobox.d.ts +106 -0
  32. package/dist/combobox.js +439 -0
  33. package/dist/controls.d.ts +82 -0
  34. package/dist/controls.js +425 -0
  35. package/dist/display.d.ts +41 -0
  36. package/dist/display.js +144 -0
  37. package/dist/fields.d.ts +24 -0
  38. package/dist/fields.js +103 -0
  39. package/dist/forms.d.ts +186 -0
  40. package/dist/forms.js +902 -0
  41. package/dist/index.d.ts +86 -0
  42. package/dist/index.js +32 -0
  43. package/dist/inputs.d.ts +107 -0
  44. package/dist/inputs.js +371 -0
  45. package/dist/iranMapData.d.ts +6 -0
  46. package/dist/iranMapData.js +37 -0
  47. package/dist/map.d.ts +64 -0
  48. package/dist/map.js +416 -0
  49. package/dist/menu.d.ts +45 -0
  50. package/dist/menu.js +281 -0
  51. package/dist/nav.d.ts +163 -0
  52. package/dist/nav.js +918 -0
  53. package/dist/overlay.d.ts +79 -0
  54. package/dist/overlay.js +420 -0
  55. package/dist/pickers.d.ts +108 -0
  56. package/dist/pickers.js +655 -0
  57. package/dist/table.d.ts +53 -0
  58. package/dist/table.js +267 -0
  59. package/dist/toast.d.ts +45 -0
  60. package/dist/toast.js +141 -0
  61. package/package.json +63 -4
package/dist/fields.js ADDED
@@ -0,0 +1,103 @@
1
+ import { onlyDigits, toFaDigits } from "@kashi-ui/persian";
2
+ import { HTMLBase, define, emit, esc, fieldHTML, setMessages, syncHidden, uid } from "./base.js";
3
+ /**
4
+ * کد تأیید یک‌بارمصرف: یک input واقعی (نه شش input جدا)، پس چسباندن، پاک کردن،
5
+ * صفحه‌خوان و پر شدن خودکار کد پیامکی (autocomplete="one-time-code") کار می‌کنند.
6
+ */
7
+ export class KashiOtp extends HTMLBase {
8
+ constructor() {
9
+ super(...arguments);
10
+ this.code = "";
11
+ this.caret = 0;
12
+ this.valueSet = false;
13
+ this.rendered = false;
14
+ this.key = uid("kashi-otp");
15
+ }
16
+ connectedCallback() {
17
+ if (!this.rendered && !this.valueSet)
18
+ this.code = onlyDigits(this.getAttribute("value") ?? "").slice(0, this.length);
19
+ this.render();
20
+ }
21
+ attributeChangedCallback(name, old, next) {
22
+ if (!this.rendered || old === next)
23
+ return;
24
+ if (name === "value") {
25
+ this.code = onlyDigits(next ?? "").slice(0, this.length);
26
+ this.paint();
27
+ }
28
+ else
29
+ this.render();
30
+ }
31
+ get value() {
32
+ return this.code;
33
+ }
34
+ set value(v) {
35
+ this.valueSet = true;
36
+ this.code = onlyDigits(String(v ?? "")).slice(0, this.length);
37
+ if (this.rendered)
38
+ this.paint();
39
+ }
40
+ focus(options) {
41
+ this.input?.focus(options);
42
+ }
43
+ get length() {
44
+ const n = Number(this.getAttribute("length"));
45
+ return Number.isInteger(n) && n > 0 ? n : 6;
46
+ }
47
+ render() {
48
+ const id = this.key;
49
+ const length = this.length;
50
+ const group = Number(this.getAttribute("group-after")) || 0;
51
+ const ariaLabel = this.getAttribute("aria-label");
52
+ const label = this.hasAttribute("label") ? this.getAttribute("label") : ariaLabel ? null : "کد تأیید";
53
+ const slots = Array.from({ length }, (_, i) => `${group && i === group ? '<span class="k-otp__sep" aria-hidden="true"></span>' : ""}<span class="k-otp__slot" aria-hidden="true"></span>`).join("");
54
+ const control = `<div class="k-otp${this.getAttribute("size") === "sm" ? " k-otp--sm" : ""}"><input id="${id}" class="k-otp__input" type="text" inputmode="numeric" autocomplete="one-time-code" pattern="\\d*" maxlength="${length * 2}"${this.hasAttribute("disabled") ? " disabled" : ""}${!label && ariaLabel ? ` aria-label="${esc(ariaLabel)}"` : ""}>${slots}</div>`;
55
+ this.querySelector(":scope > .k-field")?.remove();
56
+ this.insertAdjacentHTML("afterbegin", fieldHTML({ id, label, control }));
57
+ this.input = this.querySelector(".k-otp__input");
58
+ this.querySelector(".k-otp").addEventListener("click", () => this.input.focus());
59
+ this.input.addEventListener("input", () => {
60
+ const next = onlyDigits(this.input.value).slice(0, this.length);
61
+ const prev = this.code;
62
+ this.code = next;
63
+ this.caret = next.length;
64
+ this.paint();
65
+ if (next !== prev)
66
+ emit(this, "kashi-change", { value: next });
67
+ if (next.length === this.length && next !== prev)
68
+ emit(this, "kashi-complete", { value: next });
69
+ });
70
+ const sync = () => {
71
+ this.caret = Math.min(this.input.selectionStart ?? this.code.length, this.length);
72
+ this.paintSlots();
73
+ };
74
+ for (const t of ["select", "keyup", "focus"])
75
+ this.input.addEventListener(t, sync);
76
+ this.input.addEventListener("blur", () => this.paintSlots());
77
+ this.rendered = true;
78
+ this.paint();
79
+ }
80
+ paint() {
81
+ if (this.input.value !== this.code)
82
+ this.input.value = this.code;
83
+ this.paintSlots();
84
+ const error = this.getAttribute("error");
85
+ this.querySelector(".k-otp").classList.toggle("k-otp--invalid", !!error);
86
+ setMessages(this.querySelector(":scope > .k-field"), this.input, this.key, error, this.getAttribute("hint"));
87
+ syncHidden(this, this.getAttribute("name"), this.code);
88
+ }
89
+ /** فقط خانه‌ها؛ مقدار input را دست نمی‌زند تا تایپ کاربر پیش از رویداد input پاک نشود */
90
+ paintSlots() {
91
+ const fa = this.getAttribute("digits") !== "latin";
92
+ const focused = this.ownerDocument.activeElement === this.input;
93
+ const active = Math.min(this.caret, this.length - 1);
94
+ this.querySelectorAll(".k-otp__slot").forEach((slot, i) => {
95
+ const c = this.code[i] ?? "";
96
+ slot.textContent = fa ? toFaDigits(c) : c;
97
+ slot.toggleAttribute("data-filled", !!c);
98
+ slot.toggleAttribute("data-active", focused && i === active);
99
+ });
100
+ }
101
+ }
102
+ KashiOtp.observedAttributes = ["label", "hint", "error", "length", "digits", "group-after", "size", "disabled", "name", "value", "aria-label"];
103
+ define("kashi-otp", KashiOtp, "block");
@@ -0,0 +1,186 @@
1
+ import { type Plate } from "@kashi-ui/persian";
2
+ import { HTMLBase } from "./base.js";
3
+ import { type ComboboxOption } from "./combobox.js";
4
+ /**
5
+ * انتخاب چندتایی با جستجو: انتخاب‌ها به‌شکل برچسب، با Backspace حذف آخرین، ↑↓ و Enter برای انتخاب.
6
+ * گزینه‌ها از <option> (selected برای انتخاب اولیه) یا element.options.
7
+ */
8
+ export declare class KashiMultiSelect extends HTMLBase {
9
+ static observedAttributes: string[];
10
+ private list;
11
+ private chosen;
12
+ private query;
13
+ private active;
14
+ private isOpen;
15
+ private valueSet;
16
+ private key;
17
+ private input;
18
+ private box;
19
+ private listbox;
20
+ connectedCallback(): void;
21
+ disconnectedCallback(): void;
22
+ attributeChangedCallback(_n: string, old: string | null, next: string | null): void;
23
+ get options(): ComboboxOption[];
24
+ set options(o: ComboboxOption[]);
25
+ /** مقدار گزینه‌های انتخاب‌شده */
26
+ get value(): string[];
27
+ set value(v: string[]);
28
+ private render;
29
+ private labelOf;
30
+ private filtered;
31
+ private get full();
32
+ private toggle;
33
+ private set;
34
+ private announce;
35
+ private open;
36
+ private close;
37
+ private onOutside;
38
+ private onKey;
39
+ private paint;
40
+ private paintList;
41
+ }
42
+ /** اسلایدر روی input range بومی؛ با range دو دستگیره برای بازه (min و max) */
43
+ export declare class KashiSlider extends HTMLBase {
44
+ static observedAttributes: string[];
45
+ private lo;
46
+ private hi;
47
+ private valueSet;
48
+ private rendered;
49
+ private key;
50
+ connectedCallback(): void;
51
+ attributeChangedCallback(name: string, old: string | null, next: string | null): void;
52
+ private num;
53
+ private get min();
54
+ private get max();
55
+ private get isRange();
56
+ private readValue;
57
+ /** عدد، یا در حالت range آرایهٔ [کمینه، بیشینه] */
58
+ get value(): number | [number, number];
59
+ set value(v: number | [number, number]);
60
+ private fmt;
61
+ private render;
62
+ }
63
+ /** گروه چیپ برای فیلتر: هر فرزند <button> (با data-value، data-count) یک چیپ است؛ با single فقط یکی */
64
+ export declare class KashiChipGroup extends HTMLBase {
65
+ static observedAttributes: string[];
66
+ private built;
67
+ connectedCallback(): void;
68
+ attributeChangedCallback(): void;
69
+ /** مقدار چیپ‌های روشن */
70
+ get value(): string[];
71
+ set value(v: string[]);
72
+ private build;
73
+ private sync;
74
+ }
75
+ /** قدرت رمز زیر فیلد رمز؛ با for="شناسهٔ فیلد" به آن وصل می‌شود و با هر تایپ به‌روز می‌شود */
76
+ export declare class KashiPasswordStrength extends HTMLBase {
77
+ static observedAttributes: string[];
78
+ private target;
79
+ connectedCallback(): void;
80
+ disconnectedCallback(): void;
81
+ attributeChangedCallback(): void;
82
+ private attach;
83
+ private onInput;
84
+ /** امتیاز ۰ تا ۴ */
85
+ score(password: string): number;
86
+ private render;
87
+ }
88
+ /** پایهٔ فیلد متنی ساده با برچسب، راهنما و خطا، برای فیلدهای متنی فارسی */
89
+ declare abstract class TextField extends HTMLBase {
90
+ protected key: string;
91
+ protected control: HTMLInputElement | HTMLTextAreaElement;
92
+ protected rendered: boolean;
93
+ protected valueSet: boolean;
94
+ protected text: string;
95
+ protected abstract multiline: boolean;
96
+ protected abstract defaultLabel: string;
97
+ protected abstract hint(): string | null;
98
+ connectedCallback(): void;
99
+ attributeChangedCallback(name: string, old: string | null, next: string | null): void;
100
+ get value(): string;
101
+ set value(v: string);
102
+ focus(options?: FocusOptions): void;
103
+ protected render(): void;
104
+ /** راهنمای زیر فیلد؛ HTML ساخته‌شده توسط زیرکلاس */
105
+ protected paint(): void;
106
+ protected replace(next: string): void;
107
+ }
108
+ /** متن چندخطی با ویرایش نگارشی: ی و ک عربی، نیم‌فاصله، علامت‌ها و ارقام را می‌شمارد و با یک دکمه اصلاح می‌کند */
109
+ export declare class KashiPersianTextarea extends TextField {
110
+ static observedAttributes: string[];
111
+ protected multiline: boolean;
112
+ protected defaultLabel: string;
113
+ protected render(): void;
114
+ private result;
115
+ protected hint(): string | null;
116
+ }
117
+ /** فیلد متنی که متن تایپ‌شده با صفحه‌کلید انگلیسی را تشخیص می‌دهد و نسخهٔ فارسی‌اش را پیشنهاد می‌کند («sghl» ← «سلام») */
118
+ export declare class KashiKeyboardFix extends TextField {
119
+ static observedAttributes: string[];
120
+ protected multiline: boolean;
121
+ protected defaultLabel: string;
122
+ protected render(): void;
123
+ protected hint(): string | null;
124
+ }
125
+ /** ساعت ۲۴ساعته: ۹:۳۰، ۰۹۳۰ و ارقام فارسی را می‌فهمد؛ ↑↓ با گام step دقیقه */
126
+ export declare class KashiTimeInput extends HTMLBase {
127
+ static observedAttributes: string[];
128
+ private current;
129
+ private invalid;
130
+ private valueSet;
131
+ private rendered;
132
+ private key;
133
+ private input;
134
+ connectedCallback(): void;
135
+ attributeChangedCallback(name: string, old: string | null, next: string | null): void;
136
+ /** ساعت به شکل HH:MM، یا رشتهٔ خالی */
137
+ get value(): string;
138
+ set value(v: string);
139
+ private normal;
140
+ private show;
141
+ private get lo();
142
+ private get hi();
143
+ private render;
144
+ private commitText;
145
+ private commit;
146
+ private paint;
147
+ }
148
+ /** پلاک خودرو با چهار بخش (۱۲ ب ۳۴۵ ایران ۶۷)؛ فوکوس خودکار به بخش بعد و رنگ بر اساس نوع پلاک */
149
+ export declare class KashiPlateInput extends HTMLBase {
150
+ static observedAttributes: string[];
151
+ private plate;
152
+ private touched;
153
+ private valueSet;
154
+ private rendered;
155
+ private key;
156
+ connectedCallback(): void;
157
+ attributeChangedCallback(name: string, old: string | null, next: string | null): void;
158
+ /** «12-ب-345-67» */
159
+ private parse;
160
+ get value(): Plate;
161
+ set value(p: Plate);
162
+ get valid(): boolean;
163
+ private render;
164
+ private paint;
165
+ }
166
+ /**
167
+ * ویرایش درجا: متن با کلیک یا Enter به فیلد تبدیل می‌شود، Enter ثبت و Esc انصراف.
168
+ * رویداد kashi-save با detail.value؛ برای ذخیرهٔ سمت سرور event.detail.wait(promise) را صدا بزنید.
169
+ */
170
+ export declare class KashiInlineEdit extends HTMLBase {
171
+ static observedAttributes: string[];
172
+ private text;
173
+ private editing;
174
+ private valueSet;
175
+ private rendered;
176
+ /** اعتبارسنجی؛ پیام خطا یا undefined */
177
+ validate?: (value: string) => string | undefined;
178
+ connectedCallback(): void;
179
+ attributeChangedCallback(name: string, old: string | null, next: string | null): void;
180
+ get value(): string;
181
+ set value(v: string);
182
+ private render;
183
+ private edit;
184
+ private commit;
185
+ }
186
+ export {};