@kashi-ui/elements 2.22.0 → 2.24.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 +6 -1
- package/dist/base.js +4 -0
- package/dist/buttons.d.ts +82 -0
- package/dist/buttons.js +505 -0
- package/dist/cards.d.ts +30 -0
- package/dist/cards.js +183 -0
- package/dist/cdn/{appointment-wMGBoHw9.js → appointment-DOXBUwIU.js} +1 -1
- package/dist/cdn/{base-Dg1Mb8Jk.js → base-D4tCOysh.js} +1 -1
- package/dist/cdn/{basic-B5ZxgagA.js → basic-DuY4RslZ.js} +1 -1
- package/dist/cdn/buttons-BaK6bx3w.js +1 -0
- package/dist/cdn/calendar-BulPeVAJ.js +16 -0
- package/dist/cdn/card-BKiwJF34.js +1 -0
- package/dist/cdn/cards-DKarXHsC.js +1 -0
- package/dist/cdn/charts-ETYOAJyB.js +1 -0
- package/dist/cdn/chat-D5ZIMnNp.js +4 -0
- package/dist/cdn/choice-DBvC2Puo.js +1 -0
- package/dist/cdn/{combobox-CBT7yp94.js → combobox-BGuPAAt3.js} +1 -1
- package/dist/cdn/{commerce-CsyixnVK.js → commerce-SzWdpWJG.js} +1 -1
- package/dist/cdn/content-BgfBfy8j.js +1 -0
- package/dist/cdn/controls--OMZkJYe.js +1 -0
- package/dist/cdn/display-BfYWAjNu.js +1 -0
- package/dist/cdn/{fields-Cx84-qz1.js → fields-B-jTUQiI.js} +1 -1
- package/dist/cdn/forms-DgRiYmdV.js +1 -0
- package/dist/cdn/{holidays-DO82gXhM.js → holidays-Cu6IfbTL.js} +1 -1
- package/dist/cdn/hours-CeiVqPKD.js +1 -0
- package/dist/cdn/inputs-BkJ70Xkc.js +1 -0
- package/dist/cdn/kashi-elements.js +1 -1
- package/dist/cdn/legal-id-Mt8FX0fV.js +1 -0
- package/dist/cdn/{map-DlpA916P.js → map-TfSt3CjL.js} +2 -2
- package/dist/cdn/media-BRBINvzU.js +1 -0
- package/dist/cdn/{menu-CqTvk8Ok.js → menu-DTNVFXrb.js} +1 -1
- package/dist/cdn/money-CjGI2VIQ.js +1 -0
- package/dist/cdn/{nav-BHv7H1Fy.js → nav-CT5RVOzy.js} +1 -1
- package/dist/cdn/{overlay-BIEEJ4Sh.js → overlay-CS8piW6X.js} +1 -1
- package/dist/cdn/parts-5fVaWtRe.js +1 -0
- package/dist/cdn/pickers-BwDRsDRo.js +1 -0
- package/dist/cdn/relative-OC1fV3Xh.js +1 -0
- package/dist/cdn/rich-text-CS6xEim6.js +1 -0
- package/dist/cdn/sheets-eVMx4d-5.js +1 -0
- package/dist/cdn/{table-B5XwDDS9.js → table-tgB4iwcM.js} +1 -1
- package/dist/cdn/{text-Bml-pVjo.js → text-C6fzEBBh.js} +1 -1
- package/dist/cdn/{time-DrXgFeQy.js → time-CkqqUKJv.js} +1 -1
- package/dist/cdn/{time-BQsTSvql.js → time-CwOYrtK-.js} +1 -1
- package/dist/cdn/validate-Dr2f6i6s.js +1 -0
- package/dist/cdn/work-DoNAKgVU.js +1 -0
- package/dist/cdn.js +11 -0
- package/dist/chat.d.ts +127 -0
- package/dist/chat.js +734 -0
- package/dist/choice.d.ts +98 -0
- package/dist/choice.js +597 -0
- package/dist/content.d.ts +164 -0
- package/dist/content.js +726 -0
- package/dist/hours.d.ts +29 -0
- package/dist/hours.js +179 -0
- package/dist/index.d.ts +64 -2
- package/dist/index.js +22 -1
- package/dist/manifest.json +849 -2
- package/dist/media.d.ts +51 -0
- package/dist/media.js +363 -0
- package/dist/overlay.d.ts +2 -1
- package/dist/overlay.js +42 -11
- package/dist/parts.d.ts +31 -0
- package/dist/parts.js +114 -0
- package/dist/qr.d.ts +7 -0
- package/dist/qr.js +271 -0
- package/dist/rich-text.d.ts +40 -0
- package/dist/rich-text.js +375 -0
- package/dist/sheets.d.ts +128 -0
- package/dist/sheets.js +661 -0
- package/dist/validate.d.ts +40 -0
- package/dist/validate.js +224 -0
- package/dist/work.d.ts +117 -0
- package/dist/work.js +895 -0
- package/package.json +4 -4
- package/dist/cdn/calendar-Cjp5Rqer.js +0 -16
- package/dist/cdn/charts-DvQ4OwdS.js +0 -1
- package/dist/cdn/controls-B-s4IF_4.js +0 -1
- package/dist/cdn/display-MorJMDEF.js +0 -1
- package/dist/cdn/forms-CQeP9iiW.js +0 -1
- package/dist/cdn/inputs-Bqcs9Xy7.js +0 -1
- package/dist/cdn/pickers-BT9VPT4o.js +0 -1
package/README.md
CHANGED
|
@@ -45,7 +45,12 @@ setLocale("en"); // پیش از ساخته شدن عنصرها
|
|
|
45
45
|
- **داده و نمودار:** `kashi-data-table`، `kashi-pagination`، `kashi-bar-chart`، `kashi-line-chart`، `kashi-pie-chart`، `kashi-bar-list`، `kashi-proportion-bar`، `kashi-sparkline`، `kashi-activity-heatmap`
|
|
46
46
|
- **نمایش:** `kashi-money`، `kashi-date`، `kashi-relative-time`، `kashi-countdown`
|
|
47
47
|
- **تعاملی:** `kashi-dialog`، `kashi-tabs`، `kashi-tooltip`، `kashi-dropdown-menu`، `kashi-popover`، `kashi-context-menu`، `kashi-command-palette`، `kashi-toaster` (و تابع `toast()`)، `kashi-copy-button`
|
|
48
|
-
- **چیدمان:** `kashi-carousel`، `kashi-tree-view`، `kashi-tour`، `kashi-splitter`، `kashi-side-nav`
|
|
48
|
+
- **چیدمان:** `kashi-carousel`، `kashi-tree-view`، `kashi-tour`، `kashi-splitter`، `kashi-side-nav`، `kashi-navbar`، `kashi-breadcrumb`، `kashi-accordion`، `kashi-card`، `kashi-divider`، `kashi-drawer`، `kashi-bottom-sheet`
|
|
49
|
+
- **دکمه و انتخاب:** `kashi-button`، `kashi-button-group`، `kashi-segmented-control`، `kashi-checkbox`، `kashi-switch`، `kashi-radio-group`، `kashi-select`
|
|
50
|
+
- **وضعیت و بازخورد:** `kashi-alert`، `kashi-badge`، `kashi-avatar`، `kashi-avatar-group`، `kashi-skeleton`، `kashi-empty-state`، `kashi-progress`، `kashi-meter`، `kashi-stepper`، `kashi-timeline`، `kashi-stat-card`، `kashi-notification-center`، `kashi-notification-list`
|
|
51
|
+
- **گفتگو و هوش مصنوعی:** `kashi-chat`، `kashi-chat-message`، `kashi-typing-indicator`، `kashi-chat-composer`، `kashi-streaming-text`، `kashi-code-block`
|
|
52
|
+
- **کار و محتوا:** `kashi-sortable`، `kashi-kanban`، `kashi-scheduler`، `kashi-gallery`، `kashi-qr-code`، `kashi-rich-text`، `kashi-form` (اعتبارسنجی با `data-rules`)
|
|
53
|
+
- **نمایشهای فارسی:** `kashi-bank-card`، `kashi-receipt`، `kashi-date-tile`، `kashi-business-hours`
|
|
49
54
|
|
|
50
55
|
فایل CDN فقط بخشهایی را دانلود میکند که تگشان در صفحه هست.
|
|
51
56
|
|
package/dist/base.js
CHANGED
|
@@ -5,11 +5,13 @@ export const HTMLBase = typeof HTMLElement === "undefined" ? class {
|
|
|
5
5
|
} : HTMLElement;
|
|
6
6
|
const BLOCK_TAGS = [];
|
|
7
7
|
const CONTENTS_TAGS = [];
|
|
8
|
+
const ALL_TAGS = [];
|
|
8
9
|
let style = null;
|
|
9
10
|
/** ثبت عنصر، فقط در مرورگر و فقط یک بار (اگر پکیج دو بار بارگذاری شود خطا نمیدهد) */
|
|
10
11
|
export function define(tag, ctor, display = "inline") {
|
|
11
12
|
if (typeof customElements === "undefined" || customElements.get(tag))
|
|
12
13
|
return;
|
|
14
|
+
ALL_TAGS.push(tag);
|
|
13
15
|
if (display === "block")
|
|
14
16
|
BLOCK_TAGS.push(tag);
|
|
15
17
|
if (display === "contents")
|
|
@@ -29,6 +31,8 @@ export function define(tag, ctor, display = "inline") {
|
|
|
29
31
|
CONTENTS_TAGS.length && `:where(${CONTENTS_TAGS.join(",")}) { display: contents; }`,
|
|
30
32
|
// display بالا قاعدهٔ hidden مرورگر را از کار میاندازد؛ عنصر پنهانشده باید پنهان بماند
|
|
31
33
|
`:where(${[...BLOCK_TAGS, ...CONTENTS_TAGS].join(",")})[hidden] { display: none; }`,
|
|
34
|
+
// بخشهای داخلی که با hidden پنهان میشوند، حتی اگر کلاس k-* آنها display داشته باشد (important داخل لایه بر CSS بیرون لایه میچربد)
|
|
35
|
+
`:where(${ALL_TAGS.join(",")}) [hidden]:not([hidden="until-found"]) { display: none !important; }`,
|
|
32
36
|
].filter(Boolean);
|
|
33
37
|
style.textContent = `@layer kashi.elements { ${rules.join(" ")} }`;
|
|
34
38
|
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { HTMLBase } from "./base.js";
|
|
2
|
+
/**
|
|
3
|
+
* دکمهٔ کاشی: variant، size، shape، block، icon-only و loading (فوکوس میماند ولی کلیک نمیگیرد).
|
|
4
|
+
* یک <button> واقعی داخل عنصر است، پس type="submit" فرم را ارسال میکند؛ با href به <a> تبدیل میشود.
|
|
5
|
+
*/
|
|
6
|
+
export declare class KashiButton extends HTMLBase {
|
|
7
|
+
static observedAttributes: string[];
|
|
8
|
+
private el;
|
|
9
|
+
connectedCallback(): void;
|
|
10
|
+
attributeChangedCallback(_n: string, old: string | null, next: string | null): void;
|
|
11
|
+
/** خود <button> یا <a> داخلی */
|
|
12
|
+
get control(): HTMLElement | null;
|
|
13
|
+
focus(options?: FocusOptions): void;
|
|
14
|
+
click(): void;
|
|
15
|
+
private ensure;
|
|
16
|
+
private update;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* دکمههای چسبیده به هم؛ فرزندان <button class="k-btn"> بومیاند. label نام گروه برای صفحهخوان.
|
|
20
|
+
* با toggle="single" یا "multiple" دکمهها aria-pressed میگیرند و kashi-change مقدار data-value دکمههای فشرده را میدهد.
|
|
21
|
+
*/
|
|
22
|
+
export declare class KashiButtonGroup extends HTMLBase {
|
|
23
|
+
static observedAttributes: string[];
|
|
24
|
+
private box;
|
|
25
|
+
connectedCallback(): void;
|
|
26
|
+
attributeChangedCallback(): void;
|
|
27
|
+
private get buttons();
|
|
28
|
+
/** data-value دکمههای فشرده؛ در حالت single یک رشته */
|
|
29
|
+
get value(): string | string[];
|
|
30
|
+
set value(v: string | string[]);
|
|
31
|
+
private update;
|
|
32
|
+
private onClick;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* انتخاب یکی از چند گزینهٔ کوتاه روی رادیوهای بومی (پیمایش با کلیدهای جهت)؛ گزینهها از فرزندان <option>.
|
|
36
|
+
* value، name (برای فرم)، size="sm"، block، disabled و readonly. دستگیرهٔ انتخاب با تغییر گزینه میلغزد.
|
|
37
|
+
*/
|
|
38
|
+
export declare class KashiSegmentedControl extends HTMLBase {
|
|
39
|
+
static observedAttributes: string[];
|
|
40
|
+
private box;
|
|
41
|
+
private current;
|
|
42
|
+
private ro;
|
|
43
|
+
private key;
|
|
44
|
+
connectedCallback(): void;
|
|
45
|
+
disconnectedCallback(): void;
|
|
46
|
+
attributeChangedCallback(n: string, old: string | null, next: string | null): void;
|
|
47
|
+
get value(): string;
|
|
48
|
+
set value(v: string);
|
|
49
|
+
private build;
|
|
50
|
+
private select;
|
|
51
|
+
private update;
|
|
52
|
+
private paint;
|
|
53
|
+
private measure;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* مسیر صفحه از فرزندان <a href> (و آخری صفحهٔ فعلی، معمولاً <span>). با max-items وسط مسیر به «…» جمع میشود.
|
|
57
|
+
* data-icon-only روی یک پیوند (مثل «خانه» با آیکون) متن را فقط برای صفحهخوان نگه میدارد. separator="slash" برای «/».
|
|
58
|
+
*/
|
|
59
|
+
export declare class KashiBreadcrumb extends HTMLBase {
|
|
60
|
+
static observedAttributes: string[];
|
|
61
|
+
private nav;
|
|
62
|
+
private items;
|
|
63
|
+
private expanded;
|
|
64
|
+
connectedCallback(): void;
|
|
65
|
+
attributeChangedCallback(): void;
|
|
66
|
+
private build;
|
|
67
|
+
private update;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* آکاردئون روی <details> بومی: فرزندان <details><summary>عنوان</summary>…</details>، یا هر عنصر با data-title.
|
|
71
|
+
* type="single" باز شدن هر بخش بقیه را میبندد؛ flush بدون پسزمینه. data-open بخش را باز شروع میکند.
|
|
72
|
+
*/
|
|
73
|
+
export declare class KashiAccordion extends HTMLBase {
|
|
74
|
+
static observedAttributes: string[];
|
|
75
|
+
private box;
|
|
76
|
+
private key;
|
|
77
|
+
connectedCallback(): void;
|
|
78
|
+
attributeChangedCallback(): void;
|
|
79
|
+
private get details();
|
|
80
|
+
private build;
|
|
81
|
+
private update;
|
|
82
|
+
}
|
package/dist/buttons.js
ADDED
|
@@ -0,0 +1,505 @@
|
|
|
1
|
+
// دکمه، گروه دکمه، کنترل تکهای، مسیر صفحه و آکاردئون.
|
|
2
|
+
import { afterParse, bool, define, emit, esc, HTMLBase, msg, uid } from "./base.js";
|
|
3
|
+
import { cx } from "./parts.js";
|
|
4
|
+
// ---------- دکمه ----------
|
|
5
|
+
/** ویژگیهایی که مستقیم روی <button> یا <a> داخلی میروند */
|
|
6
|
+
const PASS = ["name", "value", "form", "target", "rel", "download", "aria-controls", "aria-expanded", "aria-haspopup", "aria-pressed", "aria-describedby", "title"];
|
|
7
|
+
/**
|
|
8
|
+
* دکمهٔ کاشی: variant، size، shape، block، icon-only و loading (فوکوس میماند ولی کلیک نمیگیرد).
|
|
9
|
+
* یک <button> واقعی داخل عنصر است، پس type="submit" فرم را ارسال میکند؛ با href به <a> تبدیل میشود.
|
|
10
|
+
*/
|
|
11
|
+
export class KashiButton extends HTMLBase {
|
|
12
|
+
constructor() {
|
|
13
|
+
super(...arguments);
|
|
14
|
+
this.el = null;
|
|
15
|
+
}
|
|
16
|
+
connectedCallback() {
|
|
17
|
+
afterParse(() => {
|
|
18
|
+
if (!this.isConnected)
|
|
19
|
+
return;
|
|
20
|
+
this.ensure();
|
|
21
|
+
this.update();
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
attributeChangedCallback(_n, old, next) {
|
|
25
|
+
if (!this.el || old === next)
|
|
26
|
+
return;
|
|
27
|
+
this.ensure();
|
|
28
|
+
this.update();
|
|
29
|
+
}
|
|
30
|
+
/** خود <button> یا <a> داخلی */
|
|
31
|
+
get control() {
|
|
32
|
+
return this.el;
|
|
33
|
+
}
|
|
34
|
+
focus(options) {
|
|
35
|
+
this.el?.focus(options);
|
|
36
|
+
}
|
|
37
|
+
click() {
|
|
38
|
+
this.el?.click();
|
|
39
|
+
}
|
|
40
|
+
ensure() {
|
|
41
|
+
const tag = this.hasAttribute("href") ? "A" : "BUTTON";
|
|
42
|
+
if (this.el?.tagName === tag)
|
|
43
|
+
return;
|
|
44
|
+
const el = document.createElement(tag);
|
|
45
|
+
el.append(...(this.el ? this.el.childNodes : this.childNodes));
|
|
46
|
+
this.el?.remove();
|
|
47
|
+
this.el = el;
|
|
48
|
+
this.append(el);
|
|
49
|
+
el.addEventListener("click", (e) => {
|
|
50
|
+
if (el.getAttribute("aria-disabled") === "true") {
|
|
51
|
+
e.preventDefault();
|
|
52
|
+
e.stopImmediatePropagation();
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
update() {
|
|
57
|
+
const el = this.el;
|
|
58
|
+
const variant = this.getAttribute("variant") ?? "secondary";
|
|
59
|
+
const size = this.getAttribute("size") ?? "md";
|
|
60
|
+
const shape = this.getAttribute("shape") ?? "default";
|
|
61
|
+
const loading = bool(this, "loading");
|
|
62
|
+
const disabled = bool(this, "disabled");
|
|
63
|
+
const native = el.tagName === "BUTTON";
|
|
64
|
+
const inactive = loading || (!native && disabled);
|
|
65
|
+
el.className = cx("k-btn", `k-btn--${variant}`, size !== "md" && `k-btn--${size}`, shape !== "default" && `k-btn--${shape}`, bool(this, "block") && "k-btn--block", bool(this, "icon-only") && "k-btn--icon");
|
|
66
|
+
el.dataset.variant = variant;
|
|
67
|
+
el.dataset.size = size;
|
|
68
|
+
if (native) {
|
|
69
|
+
const b = el;
|
|
70
|
+
b.type = this.getAttribute("type") ?? "button";
|
|
71
|
+
b.disabled = disabled;
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
const href = this.getAttribute("href");
|
|
75
|
+
if (href && !inactive)
|
|
76
|
+
el.setAttribute("href", href);
|
|
77
|
+
else
|
|
78
|
+
el.removeAttribute("href");
|
|
79
|
+
}
|
|
80
|
+
for (const a of PASS) {
|
|
81
|
+
const v = this.getAttribute(a);
|
|
82
|
+
if (v === null)
|
|
83
|
+
el.removeAttribute(a);
|
|
84
|
+
else
|
|
85
|
+
el.setAttribute(a, v);
|
|
86
|
+
}
|
|
87
|
+
const label = this.getAttribute("label");
|
|
88
|
+
if (label)
|
|
89
|
+
el.setAttribute("aria-label", label);
|
|
90
|
+
else
|
|
91
|
+
el.removeAttribute("aria-label");
|
|
92
|
+
if (inactive)
|
|
93
|
+
el.setAttribute("aria-disabled", "true");
|
|
94
|
+
else
|
|
95
|
+
el.removeAttribute("aria-disabled");
|
|
96
|
+
if (loading)
|
|
97
|
+
el.setAttribute("aria-busy", "true");
|
|
98
|
+
else
|
|
99
|
+
el.removeAttribute("aria-busy");
|
|
100
|
+
const status = el.querySelector(":scope > [data-kashi-loading]");
|
|
101
|
+
if (loading && !status)
|
|
102
|
+
el.insertAdjacentHTML("beforeend", `<span class="k-sr-only" role="status" data-kashi-loading>${esc(this.getAttribute("loading-label") ?? msg().common.loading)}</span>`);
|
|
103
|
+
else if (!loading)
|
|
104
|
+
status?.remove();
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
KashiButton.observedAttributes = ["variant", "size", "shape", "loading", "loading-label", "block", "icon-only", "disabled", "type", "href", "label", ...PASS];
|
|
108
|
+
// ---------- گروه دکمه ----------
|
|
109
|
+
/**
|
|
110
|
+
* دکمههای چسبیده به هم؛ فرزندان <button class="k-btn"> بومیاند. label نام گروه برای صفحهخوان.
|
|
111
|
+
* با toggle="single" یا "multiple" دکمهها aria-pressed میگیرند و kashi-change مقدار data-value دکمههای فشرده را میدهد.
|
|
112
|
+
*/
|
|
113
|
+
export class KashiButtonGroup extends HTMLBase {
|
|
114
|
+
constructor() {
|
|
115
|
+
super(...arguments);
|
|
116
|
+
this.box = null;
|
|
117
|
+
}
|
|
118
|
+
connectedCallback() {
|
|
119
|
+
afterParse(() => {
|
|
120
|
+
if (!this.isConnected)
|
|
121
|
+
return;
|
|
122
|
+
if (!this.box) {
|
|
123
|
+
this.box = document.createElement("div");
|
|
124
|
+
this.box.setAttribute("role", "group");
|
|
125
|
+
this.box.className = "k-btn-group";
|
|
126
|
+
this.box.append(...this.childNodes);
|
|
127
|
+
this.append(this.box);
|
|
128
|
+
this.box.addEventListener("click", (e) => this.onClick(e));
|
|
129
|
+
}
|
|
130
|
+
this.update();
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
attributeChangedCallback() {
|
|
134
|
+
if (this.box)
|
|
135
|
+
this.update();
|
|
136
|
+
}
|
|
137
|
+
get buttons() {
|
|
138
|
+
return [...this.box.querySelectorAll(":scope > .k-btn")];
|
|
139
|
+
}
|
|
140
|
+
/** data-value دکمههای فشرده؛ در حالت single یک رشته */
|
|
141
|
+
get value() {
|
|
142
|
+
const on = this.box ? this.buttons.filter((b) => b.getAttribute("aria-pressed") === "true").map((b) => b.dataset.value ?? b.textContent?.trim() ?? "") : [];
|
|
143
|
+
return this.getAttribute("toggle") === "multiple" ? on : (on[0] ?? "");
|
|
144
|
+
}
|
|
145
|
+
set value(v) {
|
|
146
|
+
const list = Array.isArray(v) ? v : [v];
|
|
147
|
+
afterParse(() => this.box && this.buttons.forEach((b) => b.setAttribute("aria-pressed", String(list.includes(b.dataset.value ?? "")))));
|
|
148
|
+
}
|
|
149
|
+
update() {
|
|
150
|
+
const label = this.getAttribute("label");
|
|
151
|
+
if (label)
|
|
152
|
+
this.box.setAttribute("aria-label", label);
|
|
153
|
+
else
|
|
154
|
+
this.box.removeAttribute("aria-label");
|
|
155
|
+
if (this.getAttribute("toggle"))
|
|
156
|
+
for (const b of this.buttons)
|
|
157
|
+
if (!b.hasAttribute("aria-pressed"))
|
|
158
|
+
b.setAttribute("aria-pressed", "false");
|
|
159
|
+
}
|
|
160
|
+
onClick(e) {
|
|
161
|
+
const mode = this.getAttribute("toggle");
|
|
162
|
+
const b = e.target.closest(".k-btn");
|
|
163
|
+
if (!mode || !b || b.parentElement !== this.box || b.disabled)
|
|
164
|
+
return;
|
|
165
|
+
const on = b.getAttribute("aria-pressed") === "true";
|
|
166
|
+
if (mode === "single")
|
|
167
|
+
for (const x of this.buttons)
|
|
168
|
+
x.setAttribute("aria-pressed", "false");
|
|
169
|
+
b.setAttribute("aria-pressed", String(!on));
|
|
170
|
+
emit(this, "kashi-change", { value: this.value });
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
KashiButtonGroup.observedAttributes = ["label", "toggle"];
|
|
174
|
+
// ---------- کنترل تکهای ----------
|
|
175
|
+
/**
|
|
176
|
+
* انتخاب یکی از چند گزینهٔ کوتاه روی رادیوهای بومی (پیمایش با کلیدهای جهت)؛ گزینهها از فرزندان <option>.
|
|
177
|
+
* value، name (برای فرم)، size="sm"، block، disabled و readonly. دستگیرهٔ انتخاب با تغییر گزینه میلغزد.
|
|
178
|
+
*/
|
|
179
|
+
export class KashiSegmentedControl extends HTMLBase {
|
|
180
|
+
constructor() {
|
|
181
|
+
super(...arguments);
|
|
182
|
+
this.box = null;
|
|
183
|
+
this.current = "";
|
|
184
|
+
this.ro = null;
|
|
185
|
+
this.key = uid("kashi-seg");
|
|
186
|
+
}
|
|
187
|
+
connectedCallback() {
|
|
188
|
+
afterParse(() => {
|
|
189
|
+
if (!this.isConnected)
|
|
190
|
+
return;
|
|
191
|
+
if (!this.box)
|
|
192
|
+
this.build();
|
|
193
|
+
this.update();
|
|
194
|
+
if (typeof ResizeObserver !== "undefined" && !this.ro) {
|
|
195
|
+
this.ro = new ResizeObserver(() => this.measure());
|
|
196
|
+
this.ro.observe(this.box);
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
disconnectedCallback() {
|
|
201
|
+
this.ro?.disconnect();
|
|
202
|
+
this.ro = null;
|
|
203
|
+
}
|
|
204
|
+
attributeChangedCallback(n, old, next) {
|
|
205
|
+
if (!this.box || old === next)
|
|
206
|
+
return;
|
|
207
|
+
if (n === "value")
|
|
208
|
+
this.select(next ?? "", false);
|
|
209
|
+
else
|
|
210
|
+
this.update();
|
|
211
|
+
}
|
|
212
|
+
get value() {
|
|
213
|
+
return this.current;
|
|
214
|
+
}
|
|
215
|
+
set value(v) {
|
|
216
|
+
if (this.box)
|
|
217
|
+
this.select(String(v ?? ""), false);
|
|
218
|
+
else
|
|
219
|
+
this.setAttribute("value", String(v ?? ""));
|
|
220
|
+
}
|
|
221
|
+
build() {
|
|
222
|
+
const opts = [...this.querySelectorAll(":scope > option")];
|
|
223
|
+
const box = document.createElement("div");
|
|
224
|
+
box.setAttribute("role", "radiogroup");
|
|
225
|
+
box.innerHTML = '<span class="k-segmented__indicator" aria-hidden="true"></span>';
|
|
226
|
+
for (const o of opts) {
|
|
227
|
+
const l = document.createElement("label");
|
|
228
|
+
l.className = "k-segmented__item";
|
|
229
|
+
const input = document.createElement("input");
|
|
230
|
+
input.type = "radio";
|
|
231
|
+
input.className = "k-sr-only";
|
|
232
|
+
input.value = o.value;
|
|
233
|
+
input.disabled = o.disabled;
|
|
234
|
+
if (o.disabled)
|
|
235
|
+
input.setAttribute("data-off", "");
|
|
236
|
+
const al = o.getAttribute("aria-label");
|
|
237
|
+
if (al)
|
|
238
|
+
input.setAttribute("aria-label", al);
|
|
239
|
+
l.append(input);
|
|
240
|
+
// محتوای option فقط متن است؛ data-icon برای SVG دلخواه
|
|
241
|
+
if (o.dataset.icon)
|
|
242
|
+
l.insertAdjacentHTML("beforeend", o.dataset.icon);
|
|
243
|
+
if (o.textContent?.trim())
|
|
244
|
+
l.append(o.textContent.trim());
|
|
245
|
+
box.append(l);
|
|
246
|
+
}
|
|
247
|
+
for (const o of opts)
|
|
248
|
+
o.remove();
|
|
249
|
+
this.current = this.getAttribute("value") ?? opts.find((o) => o.selected && o.hasAttribute("selected"))?.value ?? opts.find((o) => !o.disabled)?.value ?? "";
|
|
250
|
+
box.addEventListener("change", (e) => {
|
|
251
|
+
const input = e.target;
|
|
252
|
+
if (bool(this, "readonly")) {
|
|
253
|
+
this.paint();
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
this.select(input.value, true);
|
|
257
|
+
});
|
|
258
|
+
box.addEventListener("click", (e) => {
|
|
259
|
+
if (bool(this, "readonly") && e.target.closest("input"))
|
|
260
|
+
e.preventDefault();
|
|
261
|
+
});
|
|
262
|
+
this.append(box);
|
|
263
|
+
this.box = box;
|
|
264
|
+
}
|
|
265
|
+
select(v, user) {
|
|
266
|
+
if (v === this.current && !user)
|
|
267
|
+
return this.paint();
|
|
268
|
+
this.current = v;
|
|
269
|
+
this.paint();
|
|
270
|
+
if (user)
|
|
271
|
+
emit(this, "kashi-change", { value: v });
|
|
272
|
+
}
|
|
273
|
+
update() {
|
|
274
|
+
const box = this.box;
|
|
275
|
+
box.className = cx("k-segmented", this.getAttribute("size") === "sm" && "k-segmented--sm", bool(this, "block") && "k-segmented--block");
|
|
276
|
+
const label = this.getAttribute("label") ?? this.getAttribute("aria-label");
|
|
277
|
+
if (label)
|
|
278
|
+
box.setAttribute("aria-label", label);
|
|
279
|
+
else
|
|
280
|
+
box.removeAttribute("aria-label");
|
|
281
|
+
const ro = bool(this, "readonly");
|
|
282
|
+
box.toggleAttribute("data-readonly", ro);
|
|
283
|
+
if (ro)
|
|
284
|
+
box.setAttribute("aria-readonly", "true");
|
|
285
|
+
else
|
|
286
|
+
box.removeAttribute("aria-readonly");
|
|
287
|
+
const name = this.getAttribute("name") ?? this.key;
|
|
288
|
+
const disabled = bool(this, "disabled");
|
|
289
|
+
for (const input of box.querySelectorAll("input")) {
|
|
290
|
+
input.name = name;
|
|
291
|
+
if (disabled)
|
|
292
|
+
input.disabled = true;
|
|
293
|
+
else if (!input.hasAttribute("data-off"))
|
|
294
|
+
input.disabled = false;
|
|
295
|
+
}
|
|
296
|
+
this.paint();
|
|
297
|
+
}
|
|
298
|
+
paint() {
|
|
299
|
+
for (const input of this.box.querySelectorAll("input"))
|
|
300
|
+
input.checked = input.value === this.current;
|
|
301
|
+
this.measure();
|
|
302
|
+
}
|
|
303
|
+
measure() {
|
|
304
|
+
const box = this.box;
|
|
305
|
+
if (!box)
|
|
306
|
+
return;
|
|
307
|
+
const item = [...box.querySelectorAll(".k-segmented__item")].find((l) => l.querySelector("input").checked);
|
|
308
|
+
if (!item || !item.offsetWidth) {
|
|
309
|
+
box.removeAttribute("data-indicator");
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
box.style.setProperty("--_ix", `${item.offsetLeft}px`);
|
|
313
|
+
box.style.setProperty("--_iw", `${item.offsetWidth}px`);
|
|
314
|
+
box.setAttribute("data-indicator", "");
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
KashiSegmentedControl.observedAttributes = ["value", "name", "size", "block", "disabled", "readonly", "label", "aria-label"];
|
|
318
|
+
// ---------- مسیر صفحه ----------
|
|
319
|
+
/**
|
|
320
|
+
* مسیر صفحه از فرزندان <a href> (و آخری صفحهٔ فعلی، معمولاً <span>). با max-items وسط مسیر به «…» جمع میشود.
|
|
321
|
+
* data-icon-only روی یک پیوند (مثل «خانه» با آیکون) متن را فقط برای صفحهخوان نگه میدارد. separator="slash" برای «/».
|
|
322
|
+
*/
|
|
323
|
+
export class KashiBreadcrumb extends HTMLBase {
|
|
324
|
+
constructor() {
|
|
325
|
+
super(...arguments);
|
|
326
|
+
this.nav = null;
|
|
327
|
+
this.items = [];
|
|
328
|
+
this.expanded = false;
|
|
329
|
+
}
|
|
330
|
+
connectedCallback() {
|
|
331
|
+
afterParse(() => {
|
|
332
|
+
if (!this.isConnected)
|
|
333
|
+
return;
|
|
334
|
+
if (!this.nav)
|
|
335
|
+
this.build();
|
|
336
|
+
this.update();
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
attributeChangedCallback() {
|
|
340
|
+
if (this.nav)
|
|
341
|
+
this.update();
|
|
342
|
+
}
|
|
343
|
+
build() {
|
|
344
|
+
this.items = [...this.children].filter((c) => c instanceof HTMLElement);
|
|
345
|
+
for (const el of this.items) {
|
|
346
|
+
const iconOnly = el.hasAttribute("data-icon-only");
|
|
347
|
+
el.classList.add("k-breadcrumb__link");
|
|
348
|
+
if (iconOnly)
|
|
349
|
+
el.classList.add("k-breadcrumb__link--icon");
|
|
350
|
+
const text = [...el.childNodes].filter((n) => n.nodeType === 3 && n.textContent?.trim());
|
|
351
|
+
const label = text.map((n) => n.textContent.trim()).join(" ");
|
|
352
|
+
if (text.length) {
|
|
353
|
+
const s = document.createElement("span");
|
|
354
|
+
s.className = iconOnly ? "k-sr-only" : "k-breadcrumb__text";
|
|
355
|
+
s.textContent = label;
|
|
356
|
+
text[0].replaceWith(s);
|
|
357
|
+
for (const n of text.slice(1))
|
|
358
|
+
n.remove();
|
|
359
|
+
if (!iconOnly && !el.title)
|
|
360
|
+
el.title = label;
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
this.nav = document.createElement("nav");
|
|
364
|
+
this.nav.innerHTML = "<ol></ol>";
|
|
365
|
+
this.replaceChildren(this.nav);
|
|
366
|
+
this.nav.addEventListener("click", (e) => {
|
|
367
|
+
if (!e.target.closest("[data-expand]"))
|
|
368
|
+
return;
|
|
369
|
+
this.expanded = true;
|
|
370
|
+
this.update();
|
|
371
|
+
this.nav.querySelectorAll(".k-breadcrumb__link")[1]?.focus();
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
update() {
|
|
375
|
+
const nav = this.nav;
|
|
376
|
+
nav.className = cx("k-breadcrumb", this.getAttribute("separator") === "slash" && "k-breadcrumb--slash");
|
|
377
|
+
nav.setAttribute("aria-label", this.getAttribute("label") ?? msg().breadcrumb.label);
|
|
378
|
+
const max = Number(this.getAttribute("max-items")) || 0;
|
|
379
|
+
const items = this.items;
|
|
380
|
+
const collapse = !this.expanded && max >= 2 && items.length > max;
|
|
381
|
+
const visible = collapse ? [items[0], "…", ...items.slice(items.length - (max - 1))] : items;
|
|
382
|
+
items.forEach((el, i) => {
|
|
383
|
+
if (i === items.length - 1)
|
|
384
|
+
el.setAttribute("aria-current", "page");
|
|
385
|
+
else if (el.getAttribute("aria-current") === "page")
|
|
386
|
+
el.removeAttribute("aria-current");
|
|
387
|
+
});
|
|
388
|
+
const ol = nav.querySelector("ol");
|
|
389
|
+
ol.replaceChildren(...visible.map((it) => {
|
|
390
|
+
const li = document.createElement("li");
|
|
391
|
+
if (it === "…")
|
|
392
|
+
li.innerHTML = `<button type="button" class="k-breadcrumb__link" data-expand aria-label="${esc(this.getAttribute("expand-label") ?? msg().breadcrumb.expand)}">…</button>`;
|
|
393
|
+
else
|
|
394
|
+
li.append(it);
|
|
395
|
+
return li;
|
|
396
|
+
}));
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
KashiBreadcrumb.observedAttributes = ["max-items", "separator", "label", "expand-label"];
|
|
400
|
+
// ---------- آکاردئون ----------
|
|
401
|
+
/**
|
|
402
|
+
* آکاردئون روی <details> بومی: فرزندان <details><summary>عنوان</summary>…</details>، یا هر عنصر با data-title.
|
|
403
|
+
* type="single" باز شدن هر بخش بقیه را میبندد؛ flush بدون پسزمینه. data-open بخش را باز شروع میکند.
|
|
404
|
+
*/
|
|
405
|
+
export class KashiAccordion extends HTMLBase {
|
|
406
|
+
constructor() {
|
|
407
|
+
super(...arguments);
|
|
408
|
+
this.box = null;
|
|
409
|
+
this.key = uid("k-acc");
|
|
410
|
+
}
|
|
411
|
+
connectedCallback() {
|
|
412
|
+
afterParse(() => {
|
|
413
|
+
if (!this.isConnected)
|
|
414
|
+
return;
|
|
415
|
+
if (!this.box)
|
|
416
|
+
this.build();
|
|
417
|
+
this.update();
|
|
418
|
+
});
|
|
419
|
+
}
|
|
420
|
+
attributeChangedCallback() {
|
|
421
|
+
if (this.box)
|
|
422
|
+
this.update();
|
|
423
|
+
}
|
|
424
|
+
get details() {
|
|
425
|
+
return [...this.box.querySelectorAll(":scope > details")];
|
|
426
|
+
}
|
|
427
|
+
build() {
|
|
428
|
+
const box = document.createElement("div");
|
|
429
|
+
for (const child of [...this.children]) {
|
|
430
|
+
let d;
|
|
431
|
+
if (child.tagName === "DETAILS")
|
|
432
|
+
d = child;
|
|
433
|
+
else if (child.hasAttribute("data-title")) {
|
|
434
|
+
d = document.createElement("details");
|
|
435
|
+
d.innerHTML = "<summary></summary>";
|
|
436
|
+
const sum = d.querySelector("summary");
|
|
437
|
+
const desc = child.getAttribute("data-description");
|
|
438
|
+
if (desc) {
|
|
439
|
+
sum.innerHTML = `<span class="k-accordion__head"><span class="k-accordion__titles"><span class="k-accordion__title"></span><span class="k-accordion__description"></span></span></span>`;
|
|
440
|
+
sum.querySelector(".k-accordion__title").textContent = child.getAttribute("data-title");
|
|
441
|
+
sum.querySelector(".k-accordion__description").textContent = desc;
|
|
442
|
+
}
|
|
443
|
+
else
|
|
444
|
+
sum.textContent = child.getAttribute("data-title");
|
|
445
|
+
d.open = child.hasAttribute("data-open");
|
|
446
|
+
if (child.hasAttribute("data-disabled"))
|
|
447
|
+
d.setAttribute("data-disabled", "");
|
|
448
|
+
if (child.hasAttribute("data-value"))
|
|
449
|
+
d.dataset.value = child.getAttribute("data-value");
|
|
450
|
+
const body = document.createElement("div");
|
|
451
|
+
body.append(...child.childNodes);
|
|
452
|
+
d.append(body);
|
|
453
|
+
}
|
|
454
|
+
else
|
|
455
|
+
continue;
|
|
456
|
+
d.classList.add("k-accordion__item");
|
|
457
|
+
const summary = d.querySelector(":scope > summary");
|
|
458
|
+
summary?.classList.add("k-accordion__trigger");
|
|
459
|
+
if (d.hasAttribute("data-disabled") && summary) {
|
|
460
|
+
d.classList.add("k-accordion__item--disabled");
|
|
461
|
+
summary.setAttribute("aria-disabled", "true");
|
|
462
|
+
summary.tabIndex = -1;
|
|
463
|
+
summary.addEventListener("click", (e) => e.preventDefault());
|
|
464
|
+
}
|
|
465
|
+
const rest = [...d.childNodes].filter((n) => n !== summary);
|
|
466
|
+
const content = rest.length === 1 && rest[0] instanceof HTMLElement && rest[0].classList.contains("k-accordion__content") ? rest[0] : null;
|
|
467
|
+
if (!content) {
|
|
468
|
+
const c = document.createElement("div");
|
|
469
|
+
c.className = "k-accordion__content";
|
|
470
|
+
c.append(...rest);
|
|
471
|
+
d.append(c);
|
|
472
|
+
}
|
|
473
|
+
box.append(d);
|
|
474
|
+
}
|
|
475
|
+
this.replaceChildren(box);
|
|
476
|
+
this.box = box;
|
|
477
|
+
// رویداد toggle بالا نمیرود؛ با capture گرفته میشود
|
|
478
|
+
box.addEventListener("toggle", (e) => {
|
|
479
|
+
const d = e.target;
|
|
480
|
+
if (d.parentElement !== box)
|
|
481
|
+
return;
|
|
482
|
+
if (d.open && this.getAttribute("type") === "single")
|
|
483
|
+
for (const x of this.details)
|
|
484
|
+
if (x !== d && x.open)
|
|
485
|
+
x.open = false;
|
|
486
|
+
emit(this, "kashi-toggle", { index: this.details.indexOf(d), value: d.dataset.value, open: d.open });
|
|
487
|
+
}, true);
|
|
488
|
+
}
|
|
489
|
+
update() {
|
|
490
|
+
this.box.className = cx("k-accordion", bool(this, "flush") && "k-accordion--flush", this.getAttribute("size") === "sm" && "k-accordion--sm");
|
|
491
|
+
const single = this.getAttribute("type") === "single";
|
|
492
|
+
for (const d of this.details) {
|
|
493
|
+
if (single)
|
|
494
|
+
d.setAttribute("name", this.key);
|
|
495
|
+
else
|
|
496
|
+
d.removeAttribute("name");
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
KashiAccordion.observedAttributes = ["type", "flush", "size"];
|
|
501
|
+
define("kashi-button", KashiButton);
|
|
502
|
+
define("kashi-button-group", KashiButtonGroup);
|
|
503
|
+
define("kashi-segmented-control", KashiSegmentedControl);
|
|
504
|
+
define("kashi-breadcrumb", KashiBreadcrumb, "block");
|
|
505
|
+
define("kashi-accordion", KashiAccordion, "block");
|
package/dist/cards.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { HTMLBase } from "./base.js";
|
|
2
|
+
/** کارت بانکی با رنگ و لوگوی بانک (از شش رقم اول)، شمارهٔ چهاررقمی، holder و expiry («08/05»)؛ masked ارقام میانی را میپوشاند */
|
|
3
|
+
export declare class KashiBankCard extends HTMLBase {
|
|
4
|
+
static observedAttributes: string[];
|
|
5
|
+
connectedCallback(): void;
|
|
6
|
+
attributeChangedCallback(_n: string, old: string | null, next: string | null): void;
|
|
7
|
+
private render;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* رسید پرداخت: status (success، failed، pending)، amount و unit با مبلغ به حروف، merchant، tracking-code با دکمهٔ کپی،
|
|
11
|
+
* reference-id، card-number (پوشانده با لوگوی بانک) و date. rows='[["عنوان","مقدار"]]' ردیفهای دیگر؛ محتوای خود عنصر دکمههای پایین.
|
|
12
|
+
*/
|
|
13
|
+
export declare class KashiReceipt extends HTMLBase {
|
|
14
|
+
static observedAttributes: string[];
|
|
15
|
+
private actions;
|
|
16
|
+
private root;
|
|
17
|
+
private key;
|
|
18
|
+
private timer;
|
|
19
|
+
connectedCallback(): void;
|
|
20
|
+
disconnectedCallback(): void;
|
|
21
|
+
attributeChangedCallback(_n: string, old: string | null, next: string | null): void;
|
|
22
|
+
private render;
|
|
23
|
+
}
|
|
24
|
+
/** کاشی تاریخ شمسی به شکل برگ تقویم: date (ISO)، مناسبت تعطیل رسمی (holidays="false" بدون آن)، معادل میلادی (gregorian="false") و size */
|
|
25
|
+
export declare class KashiDateTile extends HTMLBase {
|
|
26
|
+
static observedAttributes: string[];
|
|
27
|
+
connectedCallback(): void;
|
|
28
|
+
attributeChangedCallback(_n: string, old: string | null, next: string | null): void;
|
|
29
|
+
private render;
|
|
30
|
+
}
|