@kashi-ui/elements 2.21.0 → 2.23.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 +487 -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-zhSdiaXr.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-DC5-I6hM.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 +843 -1
- package/dist/media.d.ts +51 -0
- package/dist/media.js +363 -0
- 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/dist/work.js
ADDED
|
@@ -0,0 +1,895 @@
|
|
|
1
|
+
// ابزارهای کار: فهرست کشیدنی، تابلوی کانبان و برنامهٔ هفتگی.
|
|
2
|
+
// موارد واقعی DOM جابهجا میشوند (نه ساخته شدن دوباره)، پس محتوای کاربر و رویدادهایش سر جایشان میمانند.
|
|
3
|
+
import { formatJalali, formatTime, getIranHoliday, jalaliWeekday, toJalali } from "@kashi-ui/persian";
|
|
4
|
+
import { afterParse, bool, calendarNames, define, digitsOf, emit, esc, HTMLBase, lang, msg, num, uid } from "./base.js";
|
|
5
|
+
import { flip, GRIP, icon, isRtl, jsonAttr, numAttr, toDate } from "./parts.js";
|
|
6
|
+
/** ترتیب تازه بدون جدا کردن عنصر فعال از DOM (تا فوکوس و pointer capture از دست نرود) */
|
|
7
|
+
function arrange(order, active) {
|
|
8
|
+
const k = order.indexOf(active);
|
|
9
|
+
for (const el of order.slice(0, k))
|
|
10
|
+
active.parentElement.insertBefore(el, active);
|
|
11
|
+
let ref = active;
|
|
12
|
+
for (const el of order.slice(k + 1)) {
|
|
13
|
+
ref.after(el);
|
|
14
|
+
ref = el;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
const tr = (el) => {
|
|
18
|
+
const [x = "0", y = "0"] = el.style.translate.split(" ");
|
|
19
|
+
return [parseFloat(x) || 0, parseFloat(y) || 0];
|
|
20
|
+
};
|
|
21
|
+
// ---------- فهرست کشیدنی ----------
|
|
22
|
+
/**
|
|
23
|
+
* فهرست کشیدنی: هر فرزند یک مورد است (data-id شناسه، data-label نام برای صفحهخوان). با ماوس و لمس از دستگیره بکشید،
|
|
24
|
+
* یا با کیبورد: فاصله برداشتن، کلیدهای جهت و Home/End حرکت، فاصلهٔ دوباره رها کردن و Escape لغو.
|
|
25
|
+
* پس از رها کردن kashi-change با detail.value (شناسهها به ترتیب تازه).
|
|
26
|
+
*/
|
|
27
|
+
export class KashiSortable extends HTMLBase {
|
|
28
|
+
constructor() {
|
|
29
|
+
super(...arguments);
|
|
30
|
+
this.list = null;
|
|
31
|
+
this.active = null;
|
|
32
|
+
this.mode = null;
|
|
33
|
+
this.saved = [];
|
|
34
|
+
this.drag = null;
|
|
35
|
+
this.pending = null;
|
|
36
|
+
}
|
|
37
|
+
connectedCallback() {
|
|
38
|
+
afterParse(() => {
|
|
39
|
+
if (!this.isConnected)
|
|
40
|
+
return;
|
|
41
|
+
if (!this.list)
|
|
42
|
+
this.build();
|
|
43
|
+
this.update();
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
attributeChangedCallback() {
|
|
47
|
+
if (this.list)
|
|
48
|
+
this.update();
|
|
49
|
+
}
|
|
50
|
+
get items() {
|
|
51
|
+
return [...this.list.children];
|
|
52
|
+
}
|
|
53
|
+
/** شناسهها به ترتیب فعلی */
|
|
54
|
+
get value() {
|
|
55
|
+
return this.list ? this.items.map((it) => it.dataset.id) : (this.pending ?? []);
|
|
56
|
+
}
|
|
57
|
+
set value(ids) {
|
|
58
|
+
this.pending = [...(ids ?? [])];
|
|
59
|
+
if (!this.list)
|
|
60
|
+
return;
|
|
61
|
+
const map = new Map(this.items.map((it) => [it.dataset.id, it]));
|
|
62
|
+
for (const id of this.pending) {
|
|
63
|
+
const it = map.get(id);
|
|
64
|
+
if (it)
|
|
65
|
+
this.list.append(it);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
label(it) {
|
|
69
|
+
return it.dataset.label ?? it.querySelector(".k-sortable__label")?.textContent?.trim() ?? it.textContent?.trim() ?? "";
|
|
70
|
+
}
|
|
71
|
+
build() {
|
|
72
|
+
var _a;
|
|
73
|
+
const ul = document.createElement("ul");
|
|
74
|
+
let i = 0;
|
|
75
|
+
for (const child of [...this.children]) {
|
|
76
|
+
let li;
|
|
77
|
+
if (child.tagName === "LI")
|
|
78
|
+
li = child;
|
|
79
|
+
else {
|
|
80
|
+
li = document.createElement("li");
|
|
81
|
+
for (const a of ["data-id", "data-label"])
|
|
82
|
+
if (child.hasAttribute(a))
|
|
83
|
+
li.setAttribute(a, child.getAttribute(a));
|
|
84
|
+
li.append(child);
|
|
85
|
+
}
|
|
86
|
+
li.classList.add("k-sortable__item");
|
|
87
|
+
(_a = li.dataset).id ?? (_a.id = String(++i));
|
|
88
|
+
li.dataset.flip = li.dataset.id;
|
|
89
|
+
// متن ساده در برچسب پیچیده میشود، مثل نسخهٔ React
|
|
90
|
+
const text = [...li.childNodes].filter((n) => n.nodeType === 3 && n.textContent?.trim());
|
|
91
|
+
if (text.length && text.length === [...li.childNodes].filter((n) => n.nodeType === 1 || n.textContent?.trim()).length) {
|
|
92
|
+
const s = document.createElement("span");
|
|
93
|
+
s.className = "k-sortable__label";
|
|
94
|
+
s.textContent = li.textContent.trim();
|
|
95
|
+
li.replaceChildren(s);
|
|
96
|
+
}
|
|
97
|
+
li.insertAdjacentHTML("afterbegin", `<button type="button" class="k-sortable__handle">${GRIP}</button>`);
|
|
98
|
+
ul.append(li);
|
|
99
|
+
}
|
|
100
|
+
this.replaceChildren(ul);
|
|
101
|
+
this.live = document.createElement("span");
|
|
102
|
+
this.live.className = "k-sr-only";
|
|
103
|
+
this.live.setAttribute("aria-live", "assertive");
|
|
104
|
+
this.append(this.live);
|
|
105
|
+
this.list = ul;
|
|
106
|
+
if (this.pending)
|
|
107
|
+
this.value = this.pending;
|
|
108
|
+
ul.addEventListener("keydown", (e) => this.onKey(e));
|
|
109
|
+
ul.addEventListener("pointerdown", (e) => this.onDown(e));
|
|
110
|
+
ul.addEventListener("pointermove", (e) => this.onMove(e));
|
|
111
|
+
ul.addEventListener("pointerup", (e) => this.drag?.pointer === e.pointerId && this.finish(true));
|
|
112
|
+
ul.addEventListener("pointercancel", () => this.drag && this.finish(false));
|
|
113
|
+
ul.addEventListener("focusout", () => {
|
|
114
|
+
if (this.mode !== "keyboard")
|
|
115
|
+
return;
|
|
116
|
+
setTimeout(() => {
|
|
117
|
+
if (this.mode === "keyboard" && !this.list.contains(document.activeElement))
|
|
118
|
+
this.finish(false);
|
|
119
|
+
}, 0);
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
update() {
|
|
123
|
+
const S = msg().sortable;
|
|
124
|
+
const label = this.getAttribute("label");
|
|
125
|
+
if (label)
|
|
126
|
+
this.list.setAttribute("aria-label", label);
|
|
127
|
+
else
|
|
128
|
+
this.list.removeAttribute("aria-label");
|
|
129
|
+
const disabled = bool(this, "disabled");
|
|
130
|
+
for (const it of this.items) {
|
|
131
|
+
const h = it.querySelector(":scope > .k-sortable__handle");
|
|
132
|
+
h.setAttribute("aria-label", S.handle(this.label(it)));
|
|
133
|
+
h.title = S.instructions;
|
|
134
|
+
h.disabled = disabled;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
say(fn, it) {
|
|
138
|
+
this.live.textContent = fn(this.label(it), num(this, this.items.indexOf(it) + 1), num(this, this.items.length));
|
|
139
|
+
}
|
|
140
|
+
start(it, mode) {
|
|
141
|
+
this.active = it;
|
|
142
|
+
this.mode = mode;
|
|
143
|
+
this.saved = this.items;
|
|
144
|
+
it.setAttribute("data-dragging", "");
|
|
145
|
+
it.dataset.mode = mode;
|
|
146
|
+
this.list.setAttribute("data-dragging", "");
|
|
147
|
+
if (mode === "keyboard")
|
|
148
|
+
it.querySelector(".k-sortable__handle").setAttribute("aria-pressed", "true");
|
|
149
|
+
}
|
|
150
|
+
finish(commit) {
|
|
151
|
+
const it = this.active;
|
|
152
|
+
if (!it)
|
|
153
|
+
return;
|
|
154
|
+
if (!commit) {
|
|
155
|
+
const play = flip(this.items);
|
|
156
|
+
arrange(this.saved, it);
|
|
157
|
+
play();
|
|
158
|
+
}
|
|
159
|
+
it.style.translate = "";
|
|
160
|
+
it.removeAttribute("data-dragging");
|
|
161
|
+
delete it.dataset.mode;
|
|
162
|
+
it.querySelector(".k-sortable__handle")?.removeAttribute("aria-pressed");
|
|
163
|
+
this.list.removeAttribute("data-dragging");
|
|
164
|
+
const changed = this.saved.some((x, i) => this.items[i] !== x);
|
|
165
|
+
this.active = null;
|
|
166
|
+
this.mode = null;
|
|
167
|
+
this.drag = null;
|
|
168
|
+
if (commit) {
|
|
169
|
+
this.say(msg().sortable.dropped, it);
|
|
170
|
+
if (changed)
|
|
171
|
+
emit(this, "kashi-change", { value: this.value });
|
|
172
|
+
}
|
|
173
|
+
else
|
|
174
|
+
this.live.textContent = msg().sortable.cancelled(this.label(it));
|
|
175
|
+
}
|
|
176
|
+
moveTo(it, to) {
|
|
177
|
+
const order = this.items.filter((x) => x !== it);
|
|
178
|
+
order.splice(to, 0, it);
|
|
179
|
+
const play = flip(this.items);
|
|
180
|
+
arrange(order, it);
|
|
181
|
+
play();
|
|
182
|
+
}
|
|
183
|
+
onKey(e) {
|
|
184
|
+
const h = e.target.closest(".k-sortable__handle");
|
|
185
|
+
if (!h || bool(this, "disabled"))
|
|
186
|
+
return;
|
|
187
|
+
const it = h.parentElement;
|
|
188
|
+
if (e.key === " " || e.key === "Enter") {
|
|
189
|
+
e.preventDefault();
|
|
190
|
+
if (this.active === it && this.mode === "keyboard")
|
|
191
|
+
this.finish(true);
|
|
192
|
+
else {
|
|
193
|
+
if (this.active)
|
|
194
|
+
this.finish(false);
|
|
195
|
+
this.start(it, "keyboard");
|
|
196
|
+
this.say(msg().sortable.grabbed, it);
|
|
197
|
+
}
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
if (this.active !== it || this.mode !== "keyboard")
|
|
201
|
+
return;
|
|
202
|
+
if (e.key === "Escape") {
|
|
203
|
+
e.preventDefault();
|
|
204
|
+
return this.finish(false);
|
|
205
|
+
}
|
|
206
|
+
const from = this.items.indexOf(it);
|
|
207
|
+
const last = this.items.length - 1;
|
|
208
|
+
const to = e.key === "ArrowUp" || e.key === "ArrowLeft" ? from - 1 : e.key === "ArrowDown" || e.key === "ArrowRight" ? from + 1 : e.key === "Home" ? 0 : e.key === "End" ? last : -2;
|
|
209
|
+
if (to === -2)
|
|
210
|
+
return;
|
|
211
|
+
e.preventDefault();
|
|
212
|
+
if (to < 0 || to > last || to === from)
|
|
213
|
+
return;
|
|
214
|
+
this.moveTo(it, to);
|
|
215
|
+
this.say(msg().sortable.moved, it);
|
|
216
|
+
}
|
|
217
|
+
onDown(e) {
|
|
218
|
+
const h = e.target.closest(".k-sortable__handle");
|
|
219
|
+
if (!h || bool(this, "disabled") || e.button !== 0)
|
|
220
|
+
return;
|
|
221
|
+
const it = h.parentElement;
|
|
222
|
+
h.setPointerCapture?.(e.pointerId);
|
|
223
|
+
this.drag = { grabY: e.clientY - it.getBoundingClientRect().top, pointer: e.pointerId };
|
|
224
|
+
this.start(it, "pointer");
|
|
225
|
+
}
|
|
226
|
+
onMove(e) {
|
|
227
|
+
const d = this.drag, it = this.active;
|
|
228
|
+
if (!d || !it || d.pointer !== e.pointerId)
|
|
229
|
+
return;
|
|
230
|
+
const base = it.getBoundingClientRect().top - tr(it)[1];
|
|
231
|
+
it.style.translate = `0 ${e.clientY - d.grabY - base}px`;
|
|
232
|
+
const center = e.clientY - d.grabY + it.offsetHeight / 2;
|
|
233
|
+
let to = 0;
|
|
234
|
+
for (const o of this.items) {
|
|
235
|
+
if (o === it)
|
|
236
|
+
continue;
|
|
237
|
+
const r = o.getBoundingClientRect();
|
|
238
|
+
if (center > r.top - tr(o)[1] + r.height / 2)
|
|
239
|
+
to++;
|
|
240
|
+
}
|
|
241
|
+
if (to !== this.items.indexOf(it))
|
|
242
|
+
this.moveTo(it, to);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
KashiSortable.observedAttributes = ["label", "disabled"];
|
|
246
|
+
// ---------- کانبان ----------
|
|
247
|
+
const PLUS = icon('<path d="M10 5v10M5 10h10"/>', 1.8);
|
|
248
|
+
/**
|
|
249
|
+
* تابلوی کانبان: هر فرزند <section data-column="شناسه" data-title="عنوان"> یک ستون است (data-limit سقف کارت، data-color رنگ نشانگر)
|
|
250
|
+
* و فرزندان آن کارتها (data-id، data-label). کارتها را بین ستونها بکشید یا با کیبورد: فاصله برداشتن، بالا و پایین در ستون،
|
|
251
|
+
* چپ و راست بین ستونها، فاصله رها کردن و Escape لغو. kashi-change با detail.value ({ ستون: [شناسهها] }). addable دکمهٔ افزودن (kashi-add).
|
|
252
|
+
*/
|
|
253
|
+
export class KashiKanban extends HTMLBase {
|
|
254
|
+
constructor() {
|
|
255
|
+
super(...arguments);
|
|
256
|
+
this.root = null;
|
|
257
|
+
this.active = null;
|
|
258
|
+
this.mode = null;
|
|
259
|
+
this.saved = new Map();
|
|
260
|
+
this.drag = null;
|
|
261
|
+
this.refocusing = false;
|
|
262
|
+
this.key = uid("kashi-kanban");
|
|
263
|
+
this.onWinMove = (e) => {
|
|
264
|
+
const d = this.drag;
|
|
265
|
+
if (!d || e.pointerId !== d.pointer)
|
|
266
|
+
return;
|
|
267
|
+
if (!d.started) {
|
|
268
|
+
if (Math.hypot(e.clientX - d.sx, e.clientY - d.sy) < 5)
|
|
269
|
+
return;
|
|
270
|
+
d.started = true;
|
|
271
|
+
this.start(d.card, "pointer");
|
|
272
|
+
}
|
|
273
|
+
e.preventDefault();
|
|
274
|
+
const el = d.card;
|
|
275
|
+
const [tx, ty] = tr(el);
|
|
276
|
+
const r = el.getBoundingClientRect();
|
|
277
|
+
el.style.translate = `${e.clientX - d.gx - (r.left - tx)}px ${e.clientY - d.gy - (r.top - ty)}px`;
|
|
278
|
+
const col = this.cols.find((c) => {
|
|
279
|
+
const b = c.getBoundingClientRect();
|
|
280
|
+
return e.clientX >= b.left && e.clientX <= b.right;
|
|
281
|
+
});
|
|
282
|
+
if (!col)
|
|
283
|
+
return;
|
|
284
|
+
const center = e.clientY - d.gy + el.offsetHeight / 2;
|
|
285
|
+
let index = 0;
|
|
286
|
+
for (const o of this.cards(col)) {
|
|
287
|
+
if (o === el)
|
|
288
|
+
continue;
|
|
289
|
+
const b = o.getBoundingClientRect();
|
|
290
|
+
if (center > b.top - tr(o)[1] + b.height / 2)
|
|
291
|
+
index++;
|
|
292
|
+
}
|
|
293
|
+
const cur = el.closest(".k-kanban__col");
|
|
294
|
+
if (cur !== col || this.cards(col).indexOf(el) !== index) {
|
|
295
|
+
this.place(el, col, index);
|
|
296
|
+
// جای تازه دوباره اندازهگیری میشود تا کارت زیر اشارهگر بماند
|
|
297
|
+
el.style.translate = "0 0";
|
|
298
|
+
const nr = el.getBoundingClientRect();
|
|
299
|
+
el.style.translate = `${e.clientX - d.gx - nr.left}px ${e.clientY - d.gy - nr.top}px`;
|
|
300
|
+
}
|
|
301
|
+
};
|
|
302
|
+
this.onWinUp = (e) => this.endPointer(e, false);
|
|
303
|
+
this.onWinCancel = (e) => this.endPointer(e, true);
|
|
304
|
+
}
|
|
305
|
+
connectedCallback() {
|
|
306
|
+
afterParse(() => {
|
|
307
|
+
if (!this.isConnected)
|
|
308
|
+
return;
|
|
309
|
+
if (!this.root)
|
|
310
|
+
this.build();
|
|
311
|
+
this.update();
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
disconnectedCallback() {
|
|
315
|
+
this.stopWindow();
|
|
316
|
+
}
|
|
317
|
+
attributeChangedCallback() {
|
|
318
|
+
if (this.root)
|
|
319
|
+
this.update();
|
|
320
|
+
}
|
|
321
|
+
get cols() {
|
|
322
|
+
return [...this.root.querySelectorAll(":scope > .k-kanban__col")];
|
|
323
|
+
}
|
|
324
|
+
cards(col) {
|
|
325
|
+
return [...col.querySelectorAll(":scope > .k-kanban__list > .k-kanban__card")];
|
|
326
|
+
}
|
|
327
|
+
/** { شناسهٔ ستون: [شناسهٔ کارتها] } */
|
|
328
|
+
get value() {
|
|
329
|
+
if (!this.root)
|
|
330
|
+
return {};
|
|
331
|
+
return Object.fromEntries(this.cols.map((c) => [c.dataset.column, this.cards(c).map((x) => x.dataset.id)]));
|
|
332
|
+
}
|
|
333
|
+
set value(v) {
|
|
334
|
+
afterParse(() => {
|
|
335
|
+
if (!this.root)
|
|
336
|
+
return;
|
|
337
|
+
const all = new Map(this.cols.flatMap((c) => this.cards(c)).map((x) => [x.dataset.id, x]));
|
|
338
|
+
for (const c of this.cols) {
|
|
339
|
+
const list = c.querySelector(".k-kanban__list");
|
|
340
|
+
for (const id of v[c.dataset.column] ?? []) {
|
|
341
|
+
const card = all.get(id);
|
|
342
|
+
if (card)
|
|
343
|
+
list.insertBefore(card, list.querySelector(".k-kanban__empty"));
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
this.update();
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
label(card) {
|
|
350
|
+
return card.dataset.label ?? card.querySelector(".k-kanban__label")?.textContent?.trim() ?? card.textContent?.trim() ?? "";
|
|
351
|
+
}
|
|
352
|
+
colName(col) {
|
|
353
|
+
return col.dataset.title ?? col.dataset.column ?? "";
|
|
354
|
+
}
|
|
355
|
+
build() {
|
|
356
|
+
const root = document.createElement("div");
|
|
357
|
+
root.setAttribute("role", "group");
|
|
358
|
+
let n = 0;
|
|
359
|
+
for (const sec of [...this.children].filter((c) => c.hasAttribute("data-column"))) {
|
|
360
|
+
const id = sec.dataset.column;
|
|
361
|
+
const col = document.createElement("section");
|
|
362
|
+
col.className = "k-kanban__col";
|
|
363
|
+
col.dataset.column = id;
|
|
364
|
+
for (const a of ["title", "limit", "color"])
|
|
365
|
+
if (sec.dataset[a] !== undefined)
|
|
366
|
+
col.dataset[a] = sec.dataset[a];
|
|
367
|
+
const headId = `${this.key}-${id}`;
|
|
368
|
+
col.setAttribute("aria-labelledby", headId);
|
|
369
|
+
col.innerHTML = `<header class="k-kanban__head">${sec.dataset.color ? `<span class="k-kanban__dot" style="background: ${esc(sec.dataset.color)}" aria-hidden="true"></span>` : ""}<h3 class="k-kanban__title" id="${headId}">${esc(sec.dataset.title ?? id)}</h3><span class="k-kanban__count"></span></header><ul class="k-kanban__list"></ul><span id="${headId}-hint" hidden></span>`;
|
|
370
|
+
const list = col.querySelector(".k-kanban__list");
|
|
371
|
+
for (const child of [...sec.children]) {
|
|
372
|
+
const li = document.createElement("li");
|
|
373
|
+
li.className = "k-kanban__card";
|
|
374
|
+
li.dataset.id = child.dataset.id ?? `c${++n}`;
|
|
375
|
+
li.dataset.flip = li.dataset.id;
|
|
376
|
+
if (child.dataset.label)
|
|
377
|
+
li.dataset.label = child.dataset.label;
|
|
378
|
+
const plain = child.children.length === 0;
|
|
379
|
+
li.innerHTML = `<button type="button" class="k-kanban__handle" aria-describedby="${headId}-hint">${GRIP}</button>`;
|
|
380
|
+
if (plain)
|
|
381
|
+
li.insertAdjacentHTML("beforeend", `<span class="k-kanban__label">${esc(child.textContent?.trim() ?? "")}</span>`);
|
|
382
|
+
else
|
|
383
|
+
li.append(child);
|
|
384
|
+
list.append(li);
|
|
385
|
+
}
|
|
386
|
+
root.append(col);
|
|
387
|
+
}
|
|
388
|
+
this.replaceChildren(root);
|
|
389
|
+
this.live = document.createElement("span");
|
|
390
|
+
this.live.className = "k-sr-only";
|
|
391
|
+
this.live.setAttribute("aria-live", "assertive");
|
|
392
|
+
root.append(this.live);
|
|
393
|
+
this.root = root;
|
|
394
|
+
root.addEventListener("keydown", (e) => this.onKey(e));
|
|
395
|
+
root.addEventListener("pointerdown", (e) => this.onDown(e));
|
|
396
|
+
root.addEventListener("click", (e) => {
|
|
397
|
+
const add = e.target.closest(".k-kanban__add");
|
|
398
|
+
if (add)
|
|
399
|
+
emit(this, "kashi-add", { column: add.closest(".k-kanban__col").dataset.column });
|
|
400
|
+
});
|
|
401
|
+
root.addEventListener("focusout", () => {
|
|
402
|
+
if (this.mode !== "keyboard")
|
|
403
|
+
return;
|
|
404
|
+
setTimeout(() => {
|
|
405
|
+
if (this.mode === "keyboard" && !this.refocusing && !root.contains(document.activeElement))
|
|
406
|
+
this.finish(false);
|
|
407
|
+
}, 0);
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
update() {
|
|
411
|
+
const M = msg(), K = M.kanban;
|
|
412
|
+
const root = this.root;
|
|
413
|
+
root.className = "k-kanban";
|
|
414
|
+
root.setAttribute("aria-label", this.getAttribute("label") ?? K.label);
|
|
415
|
+
root.toggleAttribute("data-dragging", !!this.active);
|
|
416
|
+
const target = this.active?.closest(".k-kanban__col");
|
|
417
|
+
for (const col of this.cols) {
|
|
418
|
+
const cards = this.cards(col);
|
|
419
|
+
const limit = col.dataset.limit !== undefined ? Number(col.dataset.limit) : undefined;
|
|
420
|
+
col.toggleAttribute("data-over", limit !== undefined && cards.length > limit);
|
|
421
|
+
col.toggleAttribute("data-target", col === target);
|
|
422
|
+
const count = col.querySelector(".k-kanban__count");
|
|
423
|
+
count.textContent = `${num(this, cards.length)}${limit !== undefined ? `/${num(this, limit)}` : ""}`;
|
|
424
|
+
count.setAttribute("aria-label", K.count(num(this, cards.length)));
|
|
425
|
+
col.querySelector(`[id$="-hint"]`).textContent = K.instructions;
|
|
426
|
+
const list = col.querySelector(".k-kanban__list");
|
|
427
|
+
const empty = list.querySelector(".k-kanban__empty");
|
|
428
|
+
if (!cards.length && !empty)
|
|
429
|
+
list.insertAdjacentHTML("beforeend", `<li class="k-kanban__empty">${esc(K.empty)}</li>`);
|
|
430
|
+
else if (cards.length)
|
|
431
|
+
empty?.remove();
|
|
432
|
+
for (const c of cards)
|
|
433
|
+
c.querySelector(".k-kanban__handle").setAttribute("aria-label", `${this.label(c)}${M.common.list}${this.colName(col)}`);
|
|
434
|
+
let add = col.querySelector(":scope > .k-kanban__add");
|
|
435
|
+
if (bool(this, "addable")) {
|
|
436
|
+
if (!add) {
|
|
437
|
+
col.querySelector(".k-kanban__list").insertAdjacentHTML("afterend", `<button type="button" class="k-kanban__add">${PLUS}<span></span></button>`);
|
|
438
|
+
add = col.querySelector(":scope > .k-kanban__add");
|
|
439
|
+
}
|
|
440
|
+
add.querySelector("span").textContent = this.getAttribute("add-label") ?? K.add;
|
|
441
|
+
}
|
|
442
|
+
else
|
|
443
|
+
add?.remove();
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
all() {
|
|
447
|
+
return this.cols.flatMap((c) => this.cards(c));
|
|
448
|
+
}
|
|
449
|
+
start(card, mode) {
|
|
450
|
+
this.active = card;
|
|
451
|
+
this.mode = mode;
|
|
452
|
+
this.saved = new Map(this.cols.map((c) => [c, this.cards(c)]));
|
|
453
|
+
card.setAttribute("data-dragging", "");
|
|
454
|
+
card.dataset.mode = mode;
|
|
455
|
+
if (mode === "keyboard")
|
|
456
|
+
card.querySelector(".k-kanban__handle").setAttribute("aria-pressed", "true");
|
|
457
|
+
this.update();
|
|
458
|
+
}
|
|
459
|
+
finish(commit) {
|
|
460
|
+
const card = this.active;
|
|
461
|
+
if (!card)
|
|
462
|
+
return;
|
|
463
|
+
const K = msg().kanban;
|
|
464
|
+
if (!commit) {
|
|
465
|
+
const play = flip(this.all());
|
|
466
|
+
for (const [col, cards] of this.saved) {
|
|
467
|
+
const list = col.querySelector(".k-kanban__list");
|
|
468
|
+
for (const c of cards)
|
|
469
|
+
list.append(c);
|
|
470
|
+
}
|
|
471
|
+
play();
|
|
472
|
+
}
|
|
473
|
+
card.style.translate = "";
|
|
474
|
+
card.removeAttribute("data-dragging");
|
|
475
|
+
delete card.dataset.mode;
|
|
476
|
+
card.querySelector(".k-kanban__handle")?.removeAttribute("aria-pressed");
|
|
477
|
+
const changed = [...this.saved].some(([col, cards]) => {
|
|
478
|
+
const now = this.cards(col);
|
|
479
|
+
return now.length !== cards.length || now.some((c, i) => c !== cards[i]);
|
|
480
|
+
});
|
|
481
|
+
this.active = null;
|
|
482
|
+
this.mode = null;
|
|
483
|
+
this.drag = null;
|
|
484
|
+
this.update();
|
|
485
|
+
const col = card.closest(".k-kanban__col");
|
|
486
|
+
if (commit) {
|
|
487
|
+
this.live.textContent = K.dropped(this.label(card), this.colName(col), num(this, this.cards(col).indexOf(card) + 1));
|
|
488
|
+
if (changed)
|
|
489
|
+
emit(this, "kashi-change", { value: this.value, id: card.dataset.id, column: col.dataset.column });
|
|
490
|
+
}
|
|
491
|
+
else
|
|
492
|
+
this.live.textContent = K.cancelled(this.label(card));
|
|
493
|
+
}
|
|
494
|
+
/** کارت را به ستون col و جای index میبرد */
|
|
495
|
+
place(card, col, index) {
|
|
496
|
+
const play = flip(this.all());
|
|
497
|
+
const list = col.querySelector(".k-kanban__list");
|
|
498
|
+
const others = this.cards(col).filter((c) => c !== card);
|
|
499
|
+
if (card.parentElement === list) {
|
|
500
|
+
others.splice(index, 0, card);
|
|
501
|
+
arrange(others, card);
|
|
502
|
+
}
|
|
503
|
+
else {
|
|
504
|
+
// جابهجایی بین ستونها عنصر را جدا میکند؛ فوکوس پس از آن برمیگردد
|
|
505
|
+
const hadFocus = card.contains(document.activeElement);
|
|
506
|
+
this.refocusing = hadFocus;
|
|
507
|
+
list.insertBefore(card, others[index] ?? list.querySelector(".k-kanban__empty"));
|
|
508
|
+
if (hadFocus)
|
|
509
|
+
card.querySelector(".k-kanban__handle").focus();
|
|
510
|
+
this.refocusing = false;
|
|
511
|
+
}
|
|
512
|
+
this.update();
|
|
513
|
+
play();
|
|
514
|
+
}
|
|
515
|
+
onKey(e) {
|
|
516
|
+
const h = e.target.closest(".k-kanban__handle");
|
|
517
|
+
if (!h)
|
|
518
|
+
return;
|
|
519
|
+
const card = h.closest(".k-kanban__card");
|
|
520
|
+
const K = msg().kanban;
|
|
521
|
+
if (e.key === " " || e.key === "Enter") {
|
|
522
|
+
e.preventDefault();
|
|
523
|
+
if (this.active === card && this.mode === "keyboard")
|
|
524
|
+
this.finish(true);
|
|
525
|
+
else {
|
|
526
|
+
if (this.active)
|
|
527
|
+
this.finish(false);
|
|
528
|
+
this.start(card, "keyboard");
|
|
529
|
+
this.live.textContent = K.grabbed(this.label(card), this.colName(card.closest(".k-kanban__col")));
|
|
530
|
+
}
|
|
531
|
+
return;
|
|
532
|
+
}
|
|
533
|
+
if (this.active !== card || this.mode !== "keyboard")
|
|
534
|
+
return;
|
|
535
|
+
if (e.key === "Escape") {
|
|
536
|
+
e.preventDefault();
|
|
537
|
+
return this.finish(false);
|
|
538
|
+
}
|
|
539
|
+
if (!["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"].includes(e.key))
|
|
540
|
+
return;
|
|
541
|
+
e.preventDefault();
|
|
542
|
+
const cols = this.cols;
|
|
543
|
+
const col = card.closest(".k-kanban__col");
|
|
544
|
+
const ci = cols.indexOf(col);
|
|
545
|
+
const index = this.cards(col).indexOf(card);
|
|
546
|
+
const rtl = isRtl(this.root);
|
|
547
|
+
const nextKey = rtl ? "ArrowLeft" : "ArrowRight";
|
|
548
|
+
let to = null;
|
|
549
|
+
if (e.key === "ArrowUp" && index > 0)
|
|
550
|
+
to = [col, index - 1];
|
|
551
|
+
else if (e.key === "ArrowDown" && index < this.cards(col).length - 1)
|
|
552
|
+
to = [col, index + 1];
|
|
553
|
+
else if ((e.key === "ArrowLeft" || e.key === "ArrowRight") && cols[ci + (e.key === nextKey ? 1 : -1)]) {
|
|
554
|
+
const target = cols[ci + (e.key === nextKey ? 1 : -1)];
|
|
555
|
+
to = [target, Math.min(index, this.cards(target).length)];
|
|
556
|
+
}
|
|
557
|
+
if (!to)
|
|
558
|
+
return;
|
|
559
|
+
this.place(card, to[0], to[1]);
|
|
560
|
+
this.live.textContent = K.moved(this.label(card), this.colName(to[0]), num(this, to[1] + 1));
|
|
561
|
+
}
|
|
562
|
+
onDown(e) {
|
|
563
|
+
if (e.button !== 0 || this.drag)
|
|
564
|
+
return;
|
|
565
|
+
const t = e.target;
|
|
566
|
+
const card = t.closest(".k-kanban__card");
|
|
567
|
+
if (!card || t.closest("a, input, textarea, select, button:not(.k-kanban__handle), [contenteditable]"))
|
|
568
|
+
return;
|
|
569
|
+
const r = card.getBoundingClientRect();
|
|
570
|
+
this.drag = { gx: e.clientX - r.left, gy: e.clientY - r.top, sx: e.clientX, sy: e.clientY, started: false, pointer: e.pointerId, card };
|
|
571
|
+
addEventListener("pointermove", this.onWinMove, { passive: false });
|
|
572
|
+
addEventListener("pointerup", this.onWinUp);
|
|
573
|
+
addEventListener("pointercancel", this.onWinCancel);
|
|
574
|
+
}
|
|
575
|
+
stopWindow() {
|
|
576
|
+
removeEventListener("pointermove", this.onWinMove);
|
|
577
|
+
removeEventListener("pointerup", this.onWinUp);
|
|
578
|
+
removeEventListener("pointercancel", this.onWinCancel);
|
|
579
|
+
}
|
|
580
|
+
endPointer(e, cancel) {
|
|
581
|
+
const d = this.drag;
|
|
582
|
+
if (!d || e.pointerId !== d.pointer)
|
|
583
|
+
return;
|
|
584
|
+
this.stopWindow();
|
|
585
|
+
if (d.started)
|
|
586
|
+
this.finish(!cancel);
|
|
587
|
+
else
|
|
588
|
+
this.drag = null;
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
KashiKanban.observedAttributes = ["label", "addable", "add-label"];
|
|
592
|
+
const day0 = (d) => new Date(d.getFullYear(), d.getMonth(), d.getDate());
|
|
593
|
+
const addDays = (d, n) => new Date(d.getFullYear(), d.getMonth(), d.getDate() + n);
|
|
594
|
+
const same = (a, b) => day0(a).getTime() === day0(b).getTime();
|
|
595
|
+
const mins = (d) => d.getHours() * 60 + d.getMinutes();
|
|
596
|
+
const isoDay = (d) => `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, "0")}-${String(d.getDate()).padStart(2, "0")}`;
|
|
597
|
+
/** «2026-11-07» به وقت محلی، نه UTC */
|
|
598
|
+
const parseDay = (v) => {
|
|
599
|
+
const m = v?.match(/^(\d{4})-(\d{2})-(\d{2})$/);
|
|
600
|
+
return m ? new Date(+m[1], +m[2] - 1, +m[3]) : toDate(v);
|
|
601
|
+
};
|
|
602
|
+
function layout(list) {
|
|
603
|
+
const sorted = [...list].sort((a, b) => a.start.getTime() - b.start.getTime() || b.end.getTime() - a.end.getTime());
|
|
604
|
+
const out = new Map();
|
|
605
|
+
let group = [], cols = [], groupEnd = 0;
|
|
606
|
+
const flush = () => {
|
|
607
|
+
for (const e of group)
|
|
608
|
+
out.get(e.id).cols = Math.max(1, cols.length);
|
|
609
|
+
group = [];
|
|
610
|
+
cols = [];
|
|
611
|
+
};
|
|
612
|
+
for (const e of sorted) {
|
|
613
|
+
if (group.length && e.start.getTime() >= groupEnd)
|
|
614
|
+
flush();
|
|
615
|
+
let c = cols.findIndex((end) => end <= e.start.getTime());
|
|
616
|
+
if (c < 0) {
|
|
617
|
+
c = cols.length;
|
|
618
|
+
cols.push(0);
|
|
619
|
+
}
|
|
620
|
+
cols[c] = e.end.getTime();
|
|
621
|
+
out.set(e.id, { col: c, cols: 1 });
|
|
622
|
+
group.push(e);
|
|
623
|
+
groupEnd = Math.max(groupEnd, e.end.getTime());
|
|
624
|
+
}
|
|
625
|
+
flush();
|
|
626
|
+
return out;
|
|
627
|
+
}
|
|
628
|
+
/**
|
|
629
|
+
* برنامهٔ هفتگی و روزانه با تقویم شمسی و شروع هفته از شنبه: events (JSON یا JavaScript)، date، view (week یا day)،
|
|
630
|
+
* start-hour، end-hour، step و holidays. رویدادهای همپوشان کنار هم و خط «اکنون».
|
|
631
|
+
* خانهٔ خالی با کلیک یا Enter رویداد kashi-slot (detail.start) میفرستد و کلید جهت بین خانهها میرود؛ کلیک روی رویداد kashi-event.
|
|
632
|
+
*/
|
|
633
|
+
export class KashiScheduler extends HTMLBase {
|
|
634
|
+
constructor() {
|
|
635
|
+
super(...arguments);
|
|
636
|
+
this.data = null;
|
|
637
|
+
this.anchor = day0(new Date());
|
|
638
|
+
this.mode = "week";
|
|
639
|
+
this.focus_ = [0, 0];
|
|
640
|
+
this.root = null;
|
|
641
|
+
this.timer = null;
|
|
642
|
+
this.key = uid("kashi-sched");
|
|
643
|
+
}
|
|
644
|
+
connectedCallback() {
|
|
645
|
+
afterParse(() => {
|
|
646
|
+
if (!this.isConnected)
|
|
647
|
+
return;
|
|
648
|
+
if (!this.root) {
|
|
649
|
+
const d = parseDay(this.getAttribute("date"));
|
|
650
|
+
if (d)
|
|
651
|
+
this.anchor = day0(d);
|
|
652
|
+
this.mode = this.getAttribute("view") === "day" ? "day" : "week";
|
|
653
|
+
this.build();
|
|
654
|
+
}
|
|
655
|
+
this.render();
|
|
656
|
+
if (!this.hasAttribute("now"))
|
|
657
|
+
this.timer ?? (this.timer = setInterval(() => !this.hasAttribute("now") && this.render(), 60000));
|
|
658
|
+
});
|
|
659
|
+
}
|
|
660
|
+
disconnectedCallback() {
|
|
661
|
+
if (this.timer)
|
|
662
|
+
clearInterval(this.timer);
|
|
663
|
+
this.timer = null;
|
|
664
|
+
}
|
|
665
|
+
attributeChangedCallback(n, old, next) {
|
|
666
|
+
if (old === next)
|
|
667
|
+
return;
|
|
668
|
+
if (n === "events")
|
|
669
|
+
this.data = null;
|
|
670
|
+
if (n === "date") {
|
|
671
|
+
const d = parseDay(next);
|
|
672
|
+
if (d)
|
|
673
|
+
this.anchor = day0(d);
|
|
674
|
+
}
|
|
675
|
+
if (n === "view")
|
|
676
|
+
this.mode = next === "day" ? "day" : "week";
|
|
677
|
+
if (this.root)
|
|
678
|
+
this.render();
|
|
679
|
+
}
|
|
680
|
+
get events() {
|
|
681
|
+
return this.data ?? jsonAttr(this, "events", []);
|
|
682
|
+
}
|
|
683
|
+
set events(v) {
|
|
684
|
+
this.data = [...(v ?? [])];
|
|
685
|
+
if (this.root)
|
|
686
|
+
this.render();
|
|
687
|
+
}
|
|
688
|
+
/** روزی که نما دور آن است */
|
|
689
|
+
get date() {
|
|
690
|
+
return this.anchor;
|
|
691
|
+
}
|
|
692
|
+
set date(d) {
|
|
693
|
+
const x = toDate(d);
|
|
694
|
+
if (!x)
|
|
695
|
+
return;
|
|
696
|
+
this.anchor = day0(x);
|
|
697
|
+
if (this.root)
|
|
698
|
+
this.render();
|
|
699
|
+
}
|
|
700
|
+
get view() {
|
|
701
|
+
return this.mode;
|
|
702
|
+
}
|
|
703
|
+
set view(v) {
|
|
704
|
+
this.mode = v === "day" ? "day" : "week";
|
|
705
|
+
if (this.root)
|
|
706
|
+
this.render();
|
|
707
|
+
}
|
|
708
|
+
setDate(d) {
|
|
709
|
+
this.anchor = day0(d);
|
|
710
|
+
this.render();
|
|
711
|
+
emit(this, "kashi-date-change", { date: isoDay(this.anchor) });
|
|
712
|
+
}
|
|
713
|
+
setMode(v) {
|
|
714
|
+
if (v === this.mode)
|
|
715
|
+
return;
|
|
716
|
+
this.mode = v;
|
|
717
|
+
this.render();
|
|
718
|
+
emit(this, "kashi-view-change", { view: v });
|
|
719
|
+
}
|
|
720
|
+
build() {
|
|
721
|
+
const root = document.createElement("div");
|
|
722
|
+
root.className = "k-sched";
|
|
723
|
+
root.innerHTML = `<div class="k-sched__bar"><div class="k-sched__nav"><button type="button" class="k-sched__icon" data-act="prev">${icon('<path d="m8 5 5 5-5 5"/>', 1.8)}</button><button type="button" class="k-btn k-btn--secondary k-btn--sm" data-act="today"></button><button type="button" class="k-sched__icon" data-act="next">${icon('<path d="m12 5-5 5 5 5"/>', 1.8)}</button></div><h2 class="k-sched__title" aria-live="polite"></h2><div class="k-segmented k-segmented--sm k-sched__views" role="radiogroup"><label class="k-segmented__item"><input type="radio" class="k-sr-only" name="${this.key}" value="week"><span></span></label><label class="k-segmented__item"><input type="radio" class="k-sr-only" name="${this.key}" value="day"><span></span></label></div></div><div class="k-sched__scroll" tabindex="-1"></div>`;
|
|
724
|
+
this.replaceChildren(root);
|
|
725
|
+
this.root = root;
|
|
726
|
+
root.querySelector(".k-sched__bar").addEventListener("click", (e) => {
|
|
727
|
+
const act = e.target.closest("[data-act]")?.dataset.act;
|
|
728
|
+
if (act === "prev" || act === "next")
|
|
729
|
+
this.setDate(addDays(this.anchor, (act === "next" ? 1 : -1) * (this.mode === "week" ? 7 : 1)));
|
|
730
|
+
else if (act === "today")
|
|
731
|
+
this.setDate(new Date());
|
|
732
|
+
});
|
|
733
|
+
root.querySelector(".k-sched__views").addEventListener("change", (e) => this.setMode(e.target.value));
|
|
734
|
+
const scroll = root.querySelector(".k-sched__scroll");
|
|
735
|
+
scroll.addEventListener("click", (e) => {
|
|
736
|
+
const t = e.target;
|
|
737
|
+
const slot = t.closest(".k-sched__slot");
|
|
738
|
+
if (slot)
|
|
739
|
+
return emit(this, "kashi-slot", { start: this.slotDate(slot).toISOString() });
|
|
740
|
+
const ev = t.closest(".k-sched__event");
|
|
741
|
+
if (ev) {
|
|
742
|
+
const found = this.list().find((x) => x.id === ev.dataset.id);
|
|
743
|
+
if (found)
|
|
744
|
+
emit(this, "kashi-event", { event: found.raw });
|
|
745
|
+
return;
|
|
746
|
+
}
|
|
747
|
+
const dn = t.closest(".k-sched__daynum");
|
|
748
|
+
if (dn) {
|
|
749
|
+
this.anchor = day0(new Date(Number(dn.dataset.time)));
|
|
750
|
+
this.mode = "day";
|
|
751
|
+
this.render();
|
|
752
|
+
emit(this, "kashi-date-change", { date: isoDay(this.anchor) });
|
|
753
|
+
emit(this, "kashi-view-change", { view: "day" });
|
|
754
|
+
}
|
|
755
|
+
});
|
|
756
|
+
scroll.addEventListener("focusin", (e) => {
|
|
757
|
+
const s = e.target.closest(".k-sched__slot");
|
|
758
|
+
if (s)
|
|
759
|
+
this.focus_ = s.dataset.slot.split("-").map(Number);
|
|
760
|
+
});
|
|
761
|
+
scroll.addEventListener("keydown", (e) => this.onKey(e));
|
|
762
|
+
}
|
|
763
|
+
get days() {
|
|
764
|
+
const start = this.mode === "week" ? addDays(this.anchor, -jalaliWeekday(this.anchor)) : this.anchor;
|
|
765
|
+
return Array.from({ length: this.mode === "week" ? 7 : 1 }, (_, i) => addDays(start, i));
|
|
766
|
+
}
|
|
767
|
+
get hours() {
|
|
768
|
+
const s = Math.max(0, Math.min(23, numAttr(this, "start-hour", 8)));
|
|
769
|
+
return [s, Math.max(s + 1, Math.min(24, numAttr(this, "end-hour", 20)))];
|
|
770
|
+
}
|
|
771
|
+
get step() {
|
|
772
|
+
return Math.max(5, numAttr(this, "step", 30));
|
|
773
|
+
}
|
|
774
|
+
slotDate(slot) {
|
|
775
|
+
const [d, s] = slot.dataset.slot.split("-").map(Number);
|
|
776
|
+
const x = this.days[d];
|
|
777
|
+
const m = this.hours[0] * 60 + s * this.step;
|
|
778
|
+
return new Date(x.getFullYear(), x.getMonth(), x.getDate(), Math.floor(m / 60), m % 60);
|
|
779
|
+
}
|
|
780
|
+
list() {
|
|
781
|
+
return this.events.flatMap((raw) => {
|
|
782
|
+
const start = toDate(raw.start), end = toDate(raw.end);
|
|
783
|
+
return start && end ? [{ ...raw, id: String(raw.id), start, end, raw }] : [];
|
|
784
|
+
});
|
|
785
|
+
}
|
|
786
|
+
t(m) {
|
|
787
|
+
const s = formatTime({ hours: Math.floor(m / 60), minutes: m % 60 });
|
|
788
|
+
return num(this, s);
|
|
789
|
+
}
|
|
790
|
+
onKey(e) {
|
|
791
|
+
const target = e.target;
|
|
792
|
+
if (!target.classList.contains("k-sched__slot"))
|
|
793
|
+
return;
|
|
794
|
+
const rtl = isRtl(this.root);
|
|
795
|
+
const [startH, endH] = this.hours;
|
|
796
|
+
const slots = Math.max(1, Math.round(((endH - startH) * 60) / this.step));
|
|
797
|
+
let [d, s] = this.focus_;
|
|
798
|
+
if (e.key === "ArrowUp")
|
|
799
|
+
s--;
|
|
800
|
+
else if (e.key === "ArrowDown")
|
|
801
|
+
s++;
|
|
802
|
+
else if (e.key === "ArrowRight")
|
|
803
|
+
d += rtl ? -1 : 1;
|
|
804
|
+
else if (e.key === "ArrowLeft")
|
|
805
|
+
d += rtl ? 1 : -1;
|
|
806
|
+
else if (e.key === "Home")
|
|
807
|
+
s = 0;
|
|
808
|
+
else if (e.key === "End")
|
|
809
|
+
s = slots - 1;
|
|
810
|
+
else
|
|
811
|
+
return;
|
|
812
|
+
e.preventDefault();
|
|
813
|
+
d = Math.max(0, Math.min(this.days.length - 1, d));
|
|
814
|
+
s = Math.max(0, Math.min(slots - 1, s));
|
|
815
|
+
this.focus_ = [d, s];
|
|
816
|
+
for (const el of this.root.querySelectorAll(".k-sched__slot[tabindex='0']"))
|
|
817
|
+
el.tabIndex = -1;
|
|
818
|
+
const next = this.root.querySelector(`[data-slot="${d}-${s}"]`);
|
|
819
|
+
if (next) {
|
|
820
|
+
next.tabIndex = 0;
|
|
821
|
+
next.focus();
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
render() {
|
|
825
|
+
const M = msg(), S = M.scheduler;
|
|
826
|
+
const locale = lang(), digits = digitsOf(this);
|
|
827
|
+
const { months, weekdays, weekdaysShort } = calendarNames();
|
|
828
|
+
const root = this.root;
|
|
829
|
+
const mode = this.mode;
|
|
830
|
+
const days = this.days;
|
|
831
|
+
const [startH, endH] = this.hours;
|
|
832
|
+
const step = this.step;
|
|
833
|
+
const slots = Math.max(1, Math.round(((endH - startH) * 60) / step));
|
|
834
|
+
const total = (endH - startH) * 60;
|
|
835
|
+
const now = toDate(this.getAttribute("now")) ?? new Date();
|
|
836
|
+
const holidays = this.getAttribute("holidays") !== "false";
|
|
837
|
+
const n = (v) => num(this, v);
|
|
838
|
+
root.dataset.view = mode;
|
|
839
|
+
root.style.setProperty("--k-sched-hour", this.getAttribute("hour-height") ?? "3.5rem");
|
|
840
|
+
// نوار بالا ثابت میماند تا فوکوس دکمهها از دست نرود
|
|
841
|
+
const bar = root.querySelector(".k-sched__bar");
|
|
842
|
+
bar.querySelector("[data-act=prev]").setAttribute("aria-label", mode === "week" ? S.prevWeek : S.prevDay);
|
|
843
|
+
bar.querySelector("[data-act=next]").setAttribute("aria-label", mode === "week" ? S.nextWeek : S.nextDay);
|
|
844
|
+
const today = bar.querySelector("[data-act=today]");
|
|
845
|
+
today.textContent = M.common.today;
|
|
846
|
+
today.setAttribute("aria-pressed", String(days.some((d) => same(d, now))));
|
|
847
|
+
const views = bar.querySelector(".k-sched__views");
|
|
848
|
+
views.setAttribute("aria-label", S.view);
|
|
849
|
+
views.querySelectorAll("input").forEach((input) => {
|
|
850
|
+
input.checked = input.value === mode;
|
|
851
|
+
input.nextElementSibling.textContent = input.value === "week" ? S.week : S.day;
|
|
852
|
+
});
|
|
853
|
+
const a = toJalali(days[0]), b = toJalali(days[days.length - 1]);
|
|
854
|
+
const and = locale === "en" ? "–" : " و ";
|
|
855
|
+
bar.querySelector(".k-sched__title").textContent = mode === "day"
|
|
856
|
+
? formatJalali(this.anchor, { style: "full", locale, digits })
|
|
857
|
+
: a.jm === b.jm ? `${months[a.jm - 1]} ${n(a.jy)}`
|
|
858
|
+
: a.jy === b.jy ? `${months[a.jm - 1]}${and}${months[b.jm - 1]} ${n(a.jy)}`
|
|
859
|
+
: `${months[a.jm - 1]} ${n(a.jy)}${and}${months[b.jm - 1]} ${n(b.jy)}`;
|
|
860
|
+
const [fd, fs] = this.focus_;
|
|
861
|
+
const focusD = Math.min(fd, days.length - 1), focusS = Math.min(fs, slots - 1);
|
|
862
|
+
const events = this.list();
|
|
863
|
+
const head = days.map((d) => {
|
|
864
|
+
const holiday = holidays ? getIranHoliday(d, { locale }) : null;
|
|
865
|
+
return `<div class="k-sched__dayhead"${same(d, now) ? " data-today" : ""}${holiday ? ` data-holiday title="${esc(holiday)}"` : ""}><span class="k-sched__weekday">${esc(mode === "week" ? weekdaysShort[jalaliWeekday(d)] : weekdays[jalaliWeekday(d)])}</span><button type="button" class="k-sched__daynum" data-time="${d.getTime()}" aria-label="${esc(formatJalali(d, { style: "full", locale, digits }))}">${n(toJalali(d).jd)}</button></div>`;
|
|
866
|
+
}).join("");
|
|
867
|
+
const times = Array.from({ length: endH - startH }, (_, h) => `<span class="k-sched__time">${this.t((startH + h) * 60)}</span>`).join("");
|
|
868
|
+
const cols = days.map((d, di) => {
|
|
869
|
+
const list = events.filter((e) => same(e.start, d) && mins(e.end) > startH * 60 && mins(e.start) < endH * 60);
|
|
870
|
+
const pos = layout(list);
|
|
871
|
+
const isToday = same(d, now);
|
|
872
|
+
const nowMin = mins(now) - startH * 60;
|
|
873
|
+
const slotHtml = Array.from({ length: slots }, (_, s) => `<button type="button" class="k-sched__slot" data-slot="${di}-${s}"${(s * step) % 60 === 0 ? " data-hour" : ""} tabindex="${di === focusD && s === focusS ? 0 : -1}" aria-label="${esc(S.slot(weekdays[jalaliWeekday(d)], this.t(startH * 60 + s * step)))}"></button>`).join("");
|
|
874
|
+
const evHtml = list.map((e) => {
|
|
875
|
+
const p = pos.get(e.id);
|
|
876
|
+
const top = Math.max(0, mins(e.start) - startH * 60);
|
|
877
|
+
const end = Math.min(total, mins(e.end) - startH * 60);
|
|
878
|
+
return `<button type="button" class="k-sched__event" data-id="${esc(e.id)}" style="--k-sched-top: ${top / total}; --k-sched-len: ${Math.max(15, end - top) / total}; --k-sched-col: ${p.col}; --k-sched-cols: ${p.cols}; --k-sched-color: ${esc(e.color ?? "var(--k-bg-brand)")}"${end - top < 45 ? " data-short" : ""}><span class="k-sched__event-title" dir="auto">${esc(e.title)}</span><span class="k-sched__event-time"><span class="k-sr-only">${esc(M.common.list)}</span>${this.t(mins(e.start))} – ${this.t(mins(e.end))}</span>${e.description ? `<span class="k-sched__event-desc" dir="auto">${esc(e.description)}</span>` : ""}</button>`;
|
|
879
|
+
}).join("");
|
|
880
|
+
const nowLine = isToday && nowMin >= 0 && nowMin <= total ? `<span class="k-sched__now" style="--k-sched-top: ${nowMin / total}" role="img" aria-label="${esc(`${S.now} ${this.t(mins(now))}`)}"></span>` : "";
|
|
881
|
+
return `<div class="k-sched__col" role="group" aria-label="${esc(formatJalali(d, { style: "full", locale, digits }))}"${isToday ? " data-today" : ""}${holidays && getIranHoliday(d) ? " data-holiday" : ""}>${slotHtml}${evHtml}${nowLine}</div>`;
|
|
882
|
+
}).join("");
|
|
883
|
+
const scroll = root.querySelector(".k-sched__scroll");
|
|
884
|
+
const keep = scroll.scrollTop;
|
|
885
|
+
const focused = scroll.contains(document.activeElement) ? document.activeElement.dataset.slot : undefined;
|
|
886
|
+
scroll.innerHTML = `<div class="k-sched__grid" style="--k-sched-days: ${days.length}; --k-sched-slots: ${slots}; --k-sched-hours: ${endH - startH}"><div class="k-sched__corner" aria-hidden="true"></div>${head}<div class="k-sched__times" aria-hidden="true">${times}</div><div class="k-sched__body" role="group" aria-label="${esc(S.label)}">${cols}</div></div>`;
|
|
887
|
+
scroll.scrollTop = keep;
|
|
888
|
+
if (focused)
|
|
889
|
+
scroll.querySelector(`[data-slot="${focused}"]`)?.focus();
|
|
890
|
+
}
|
|
891
|
+
}
|
|
892
|
+
KashiScheduler.observedAttributes = ["events", "date", "view", "start-hour", "end-hour", "step", "holidays", "now", "hour-height", "digits"];
|
|
893
|
+
define("kashi-sortable", KashiSortable, "block");
|
|
894
|
+
define("kashi-kanban", KashiKanban, "block");
|
|
895
|
+
define("kashi-scheduler", KashiScheduler, "block");
|