@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
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
// ویرایشگر متن غنی سبک و فارسی.
|
|
2
|
+
import { afterParse, define, emit, esc, HTMLBase, msg, num, syncHidden, uid } from "./base.js";
|
|
3
|
+
import { icon, isRtl } from "./parts.js";
|
|
4
|
+
const DEFAULT_TOOLS = ["bold", "italic", "underline", "strike", "|", "heading", "quote", "bullet", "ordered", "|", "link", "direction", "|", "undo", "clear"];
|
|
5
|
+
const ALLOWED = new Set(["P", "BR", "B", "STRONG", "I", "EM", "U", "S", "STRIKE", "DEL", "A", "UL", "OL", "LI", "H2", "H3", "BLOCKQUOTE", "DIV", "SPAN", "CODE"]);
|
|
6
|
+
const BLOCKS = "p, li, h2, h3, blockquote, div";
|
|
7
|
+
/** پاکسازی HTML: فقط برچسبهای متنی مجاز، پیوندهای http، https و mailto، و ویژگی dir */
|
|
8
|
+
export function sanitizeRichText(html) {
|
|
9
|
+
const tpl = document.createElement("template");
|
|
10
|
+
tpl.innerHTML = html;
|
|
11
|
+
const walk = (node) => {
|
|
12
|
+
for (const child of [...node.childNodes]) {
|
|
13
|
+
if (child.nodeType === 8) {
|
|
14
|
+
child.remove();
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
if (child.nodeType !== 1)
|
|
18
|
+
continue;
|
|
19
|
+
const el = child;
|
|
20
|
+
if (!ALLOWED.has(el.tagName)) {
|
|
21
|
+
if (/^(SCRIPT|STYLE|IFRAME|OBJECT|EMBED|TEMPLATE|SVG|MATH|HEAD|TITLE|META|LINK)$/i.test(el.tagName))
|
|
22
|
+
el.remove();
|
|
23
|
+
else {
|
|
24
|
+
walk(el);
|
|
25
|
+
el.replaceWith(...el.childNodes);
|
|
26
|
+
}
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
for (const attr of [...el.attributes]) {
|
|
30
|
+
const keep = (attr.name === "dir" && /^(rtl|ltr|auto)$/.test(attr.value)) || (el.tagName === "A" && attr.name === "href" && /^(https?:|mailto:)/i.test(attr.value.trim()));
|
|
31
|
+
if (!keep)
|
|
32
|
+
el.removeAttribute(attr.name);
|
|
33
|
+
}
|
|
34
|
+
if (el.tagName === "A") {
|
|
35
|
+
if (!el.hasAttribute("href")) {
|
|
36
|
+
el.replaceWith(...el.childNodes);
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
el.setAttribute("rel", "noopener noreferrer nofollow");
|
|
40
|
+
}
|
|
41
|
+
walk(el);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
walk(tpl.content);
|
|
45
|
+
return tpl.innerHTML;
|
|
46
|
+
}
|
|
47
|
+
const I = (d) => icon(d, 1.8);
|
|
48
|
+
const ICONS = {
|
|
49
|
+
bold: I('<path d="M6 4h5a3 3 0 0 1 0 6H6zm0 6h6a3 3 0 0 1 0 6H6z"/>'),
|
|
50
|
+
italic: I('<path d="M12 4H8.5M11.5 16H8M11 4 9 16"/>'),
|
|
51
|
+
underline: I('<path d="M6 4v5a4 4 0 0 0 8 0V4M5 17h10"/>'),
|
|
52
|
+
strike: I('<path d="M4 10h12M13.5 6.5c-.5-1.5-2-2.5-3.7-2.5C7.9 4 6.5 5.1 6.5 6.6c0 3.4 7 2 7 6.3 0 1.7-1.6 3.1-3.6 3.1-1.9 0-3.4-1-3.9-2.6"/>'),
|
|
53
|
+
heading: I('<path d="M5 4v12M13 4v12M5 10h8M15.5 16v-5l-1.5 1"/>'),
|
|
54
|
+
quote: I('<path d="M8 8H5v3h2.5c0 2-1 3-2.5 3.5M15 8h-3v3h2.5c0 2-1 3-2.5 3.5"/>'),
|
|
55
|
+
bullet: I('<path d="M8 5.5h8M8 10h8M8 14.5h8M4.5 5.5h.01M4.5 10h.01M4.5 14.5h.01"/>'),
|
|
56
|
+
ordered: I('<path d="M8 5.5h8M8 10h8M8 14.5h8M4 4.5l1-.5v3M4 12.5c0-.6.5-1 1-1s1 .4 1 1c0 .7-2 1.5-2 2.5h2"/>'),
|
|
57
|
+
link: I('<path d="M8.5 11.5a3 3 0 0 0 4.2 0l2.6-2.6a3 3 0 0 0-4.2-4.2L10 5.8M11.5 8.5a3 3 0 0 0-4.2 0l-2.6 2.6a3 3 0 0 0 4.2 4.2l1.1-1.1"/>'),
|
|
58
|
+
undo: I('<path d="M7 5 4 8l3 3M4 8h8a4 4 0 0 1 0 8H9"/>'),
|
|
59
|
+
clear: I('<path d="M5 4h10M10 4l-2.5 12M4 16l12-12"/>'),
|
|
60
|
+
direction: I('<path d="M9 4h6M13 4v12M9 4v8a3 3 0 0 1-3-3 3 3 0 0 1 3-3M4 14l2 2 2-2"/>'),
|
|
61
|
+
};
|
|
62
|
+
const q = (c) => {
|
|
63
|
+
try {
|
|
64
|
+
return document.queryCommandState(c);
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* ویرایشگر متن غنی فارسی: جهت هر بند جدا، نیمفاصله با Shift+Space، چسباندن پاکشده و نوار ابزار با کلیدهای جهت.
|
|
72
|
+
* value (HTML، پاکسازی میشود) یا HTML داخل عنصر، label، placeholder، tools="bold italic | link"، min-height، show-count، name، hint، error و disabled.
|
|
73
|
+
* kashi-change با detail { value: HTML، text }.
|
|
74
|
+
*/
|
|
75
|
+
export class KashiRichText extends HTMLBase {
|
|
76
|
+
constructor() {
|
|
77
|
+
super(...arguments);
|
|
78
|
+
this.root = null;
|
|
79
|
+
this.html = "";
|
|
80
|
+
this.saved = null;
|
|
81
|
+
this.state = {};
|
|
82
|
+
this.focusTool = 0;
|
|
83
|
+
this.key = uid("kashi-rte");
|
|
84
|
+
this.onSelection = () => {
|
|
85
|
+
const sel = document.getSelection();
|
|
86
|
+
if (!sel || !this.area?.contains(sel.anchorNode))
|
|
87
|
+
return;
|
|
88
|
+
const node = sel.anchorNode instanceof Element ? sel.anchorNode : sel.anchorNode?.parentElement;
|
|
89
|
+
const block = node?.closest(BLOCKS);
|
|
90
|
+
this.state = {
|
|
91
|
+
bold: q("bold"), italic: q("italic"), underline: q("underline"), strike: q("strikeThrough"),
|
|
92
|
+
bullet: q("insertUnorderedList"), ordered: q("insertOrderedList"),
|
|
93
|
+
heading: !!block?.closest("h2, h3"), quote: !!block?.closest("blockquote"),
|
|
94
|
+
link: !!node?.closest("a"), ltr: block?.dir === "ltr",
|
|
95
|
+
};
|
|
96
|
+
this.paintTools();
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
connectedCallback() {
|
|
100
|
+
afterParse(() => {
|
|
101
|
+
if (!this.isConnected)
|
|
102
|
+
return;
|
|
103
|
+
if (!this.root) {
|
|
104
|
+
if (!this.html)
|
|
105
|
+
this.html = sanitizeRichText(this.getAttribute("value") ?? this.innerHTML.trim());
|
|
106
|
+
this.build();
|
|
107
|
+
}
|
|
108
|
+
this.update();
|
|
109
|
+
document.addEventListener("selectionchange", this.onSelection);
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
disconnectedCallback() {
|
|
113
|
+
document.removeEventListener("selectionchange", this.onSelection);
|
|
114
|
+
}
|
|
115
|
+
attributeChangedCallback(n, old, next) {
|
|
116
|
+
if (!this.root || old === next)
|
|
117
|
+
return;
|
|
118
|
+
if (n === "value")
|
|
119
|
+
this.value = next ?? "";
|
|
120
|
+
else if (n === "tools")
|
|
121
|
+
this.renderBar();
|
|
122
|
+
else
|
|
123
|
+
this.update();
|
|
124
|
+
}
|
|
125
|
+
/** HTML پاکشده */
|
|
126
|
+
get value() {
|
|
127
|
+
return this.html;
|
|
128
|
+
}
|
|
129
|
+
set value(v) {
|
|
130
|
+
this.html = sanitizeRichText(String(v ?? ""));
|
|
131
|
+
if (!this.root)
|
|
132
|
+
return;
|
|
133
|
+
if (this.area.innerHTML !== this.html)
|
|
134
|
+
this.area.innerHTML = this.html;
|
|
135
|
+
this.update();
|
|
136
|
+
}
|
|
137
|
+
/** متن ساده */
|
|
138
|
+
get text() {
|
|
139
|
+
return (this.area?.innerText ?? this.area?.textContent ?? "").trim();
|
|
140
|
+
}
|
|
141
|
+
focus(options) {
|
|
142
|
+
this.area?.focus(options);
|
|
143
|
+
}
|
|
144
|
+
get tools() {
|
|
145
|
+
const t = this.getAttribute("tools");
|
|
146
|
+
return t ? t.split(/[\s,]+/).filter(Boolean) : DEFAULT_TOOLS;
|
|
147
|
+
}
|
|
148
|
+
build() {
|
|
149
|
+
const id = this.key;
|
|
150
|
+
const root = document.createElement("div");
|
|
151
|
+
root.innerHTML = `<label class="k-label k-rte__label" id="${id}-label"></label><div class="k-rte__box"><div class="k-rte__bar" role="toolbar" aria-controls="${id}"></div><form class="k-rte__link" hidden><input class="k-rte__link-input" type="url" dir="ltr" value="https://"><button type="submit" class="k-btn k-btn--primary k-btn--xs"></button></form><div id="${id}" class="k-rte__area" role="textbox" aria-multiline="true" aria-describedby="${id}-help" dir="rtl"></div><div class="k-rte__foot"></div></div><div id="${id}-help" class="k-rte__help"></div>`;
|
|
152
|
+
this.replaceChildren(root);
|
|
153
|
+
this.root = root;
|
|
154
|
+
this.area = root.querySelector(".k-rte__area");
|
|
155
|
+
this.bar = root.querySelector(".k-rte__bar");
|
|
156
|
+
this.area.innerHTML = this.html;
|
|
157
|
+
try {
|
|
158
|
+
document.execCommand("defaultParagraphSeparator", false, "p");
|
|
159
|
+
}
|
|
160
|
+
catch { /* */ }
|
|
161
|
+
root.querySelector("label").addEventListener("click", () => this.area.focus());
|
|
162
|
+
this.area.addEventListener("input", () => this.emitChange());
|
|
163
|
+
this.area.addEventListener("blur", () => this.emitChange(false));
|
|
164
|
+
this.area.addEventListener("keydown", (e) => {
|
|
165
|
+
if (e.key === " " && e.shiftKey) {
|
|
166
|
+
e.preventDefault();
|
|
167
|
+
document.execCommand("insertText", false, "");
|
|
168
|
+
}
|
|
169
|
+
if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === "k") {
|
|
170
|
+
e.preventDefault();
|
|
171
|
+
this.run("link");
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
this.area.addEventListener("paste", (e) => {
|
|
175
|
+
e.preventDefault();
|
|
176
|
+
const rich = e.clipboardData?.getData("text/html");
|
|
177
|
+
if (rich)
|
|
178
|
+
document.execCommand("insertHTML", false, sanitizeRichText(rich));
|
|
179
|
+
else
|
|
180
|
+
document.execCommand("insertText", false, e.clipboardData?.getData("text/plain") ?? "");
|
|
181
|
+
this.emitChange();
|
|
182
|
+
});
|
|
183
|
+
this.bar.addEventListener("mousedown", (e) => e.preventDefault());
|
|
184
|
+
this.bar.addEventListener("click", (e) => {
|
|
185
|
+
const b = e.target.closest(".k-rte__tool");
|
|
186
|
+
if (!b)
|
|
187
|
+
return;
|
|
188
|
+
this.focusTool = Number(b.dataset.index);
|
|
189
|
+
this.syncTabStops();
|
|
190
|
+
this.run(b.dataset.tool);
|
|
191
|
+
});
|
|
192
|
+
this.bar.addEventListener("keydown", (e) => {
|
|
193
|
+
if (!["ArrowRight", "ArrowLeft", "Home", "End"].includes(e.key))
|
|
194
|
+
return;
|
|
195
|
+
e.preventDefault();
|
|
196
|
+
const count = this.bar.querySelectorAll(".k-rte__tool").length;
|
|
197
|
+
const rtl = isRtl(this.bar);
|
|
198
|
+
const step = (e.key === "ArrowLeft") === rtl ? 1 : -1;
|
|
199
|
+
this.focusTool = e.key === "Home" ? 0 : e.key === "End" ? count - 1 : Math.max(0, Math.min(count - 1, this.focusTool + step));
|
|
200
|
+
this.syncTabStops();
|
|
201
|
+
this.bar.querySelectorAll(".k-rte__tool")[this.focusTool]?.focus();
|
|
202
|
+
});
|
|
203
|
+
const form = root.querySelector(".k-rte__link");
|
|
204
|
+
const input = form.querySelector("input");
|
|
205
|
+
form.addEventListener("submit", (e) => {
|
|
206
|
+
e.preventDefault();
|
|
207
|
+
e.stopPropagation();
|
|
208
|
+
form.hidden = true;
|
|
209
|
+
const url = input.value.trim();
|
|
210
|
+
if (/^(https?:\/\/|mailto:)\S+$/i.test(url))
|
|
211
|
+
this.exec("createLink", url);
|
|
212
|
+
else
|
|
213
|
+
this.area.focus();
|
|
214
|
+
});
|
|
215
|
+
input.addEventListener("keydown", (e) => {
|
|
216
|
+
if (e.key === "Escape") {
|
|
217
|
+
e.preventDefault();
|
|
218
|
+
e.stopPropagation();
|
|
219
|
+
form.hidden = true;
|
|
220
|
+
this.area.focus();
|
|
221
|
+
}
|
|
222
|
+
else if (e.key === "Enter") {
|
|
223
|
+
// فرم داخلی نباید فرم والد صفحه را ارسال کند
|
|
224
|
+
e.preventDefault();
|
|
225
|
+
form.requestSubmit?.() ?? form.dispatchEvent(new Event("submit", { cancelable: true }));
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
this.renderBar();
|
|
229
|
+
}
|
|
230
|
+
renderBar() {
|
|
231
|
+
const tools = this.tools;
|
|
232
|
+
let b = -1;
|
|
233
|
+
this.bar.innerHTML = tools.map((t) => {
|
|
234
|
+
if (t === "|")
|
|
235
|
+
return '<span class="k-rte__sep" aria-hidden="true"></span>';
|
|
236
|
+
if (!ICONS[t])
|
|
237
|
+
return "";
|
|
238
|
+
b++;
|
|
239
|
+
return `<button type="button" class="k-rte__tool" data-tool="${t}" data-index="${b}" tabindex="${b === this.focusTool ? 0 : -1}">${ICONS[t]}</button>`;
|
|
240
|
+
}).join("");
|
|
241
|
+
this.paintTools();
|
|
242
|
+
}
|
|
243
|
+
syncTabStops() {
|
|
244
|
+
this.bar.querySelectorAll(".k-rte__tool").forEach((b, i) => (b.tabIndex = i === this.focusTool ? 0 : -1));
|
|
245
|
+
}
|
|
246
|
+
paintTools() {
|
|
247
|
+
const R = msg().richText;
|
|
248
|
+
const disabled = this.hasAttribute("disabled");
|
|
249
|
+
for (const b of this.bar.querySelectorAll(".k-rte__tool")) {
|
|
250
|
+
const t = b.dataset.tool;
|
|
251
|
+
const label = t === "direction" ? (this.state.ltr ? R.rtl : R.ltr) : t === "link" && this.state.link ? R.unlink : R[t];
|
|
252
|
+
b.setAttribute("aria-label", label);
|
|
253
|
+
b.title = label;
|
|
254
|
+
b.disabled = disabled;
|
|
255
|
+
if (t === "direction")
|
|
256
|
+
b.setAttribute("aria-pressed", String(!!this.state.ltr));
|
|
257
|
+
else if (t !== "link" && t !== "undo" && t !== "clear")
|
|
258
|
+
b.setAttribute("aria-pressed", String(!!this.state[t]));
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
exec(cmd, arg) {
|
|
262
|
+
this.area.focus();
|
|
263
|
+
if (this.saved) {
|
|
264
|
+
const sel = document.getSelection();
|
|
265
|
+
sel?.removeAllRanges();
|
|
266
|
+
sel?.addRange(this.saved);
|
|
267
|
+
this.saved = null;
|
|
268
|
+
}
|
|
269
|
+
document.execCommand(cmd, false, arg);
|
|
270
|
+
this.emitChange();
|
|
271
|
+
}
|
|
272
|
+
run(tool) {
|
|
273
|
+
const s = this.state;
|
|
274
|
+
switch (tool) {
|
|
275
|
+
case "bold": return this.exec("bold");
|
|
276
|
+
case "italic": return this.exec("italic");
|
|
277
|
+
case "underline": return this.exec("underline");
|
|
278
|
+
case "strike": return this.exec("strikeThrough");
|
|
279
|
+
case "heading": return this.exec("formatBlock", s.heading ? "<p>" : "<h2>");
|
|
280
|
+
case "quote": return this.exec("formatBlock", s.quote ? "<p>" : "<blockquote>");
|
|
281
|
+
case "bullet": return this.exec("insertUnorderedList");
|
|
282
|
+
case "ordered": return this.exec("insertOrderedList");
|
|
283
|
+
case "undo": return this.exec("undo");
|
|
284
|
+
case "clear": return this.exec("removeFormat");
|
|
285
|
+
case "direction": {
|
|
286
|
+
const sel = document.getSelection();
|
|
287
|
+
const node = sel?.anchorNode;
|
|
288
|
+
const b = (node instanceof Element ? node : node?.parentElement)?.closest(BLOCKS);
|
|
289
|
+
if (b && this.area.contains(b) && b !== this.area) {
|
|
290
|
+
b.dir = b.dir === "ltr" ? "rtl" : "ltr";
|
|
291
|
+
this.state.ltr = b.dir === "ltr";
|
|
292
|
+
this.paintTools();
|
|
293
|
+
this.emitChange();
|
|
294
|
+
}
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
case "link": {
|
|
298
|
+
if (s.link)
|
|
299
|
+
return this.exec("unlink");
|
|
300
|
+
const sel = document.getSelection();
|
|
301
|
+
if (sel && sel.rangeCount && this.area.contains(sel.anchorNode))
|
|
302
|
+
this.saved = sel.getRangeAt(0).cloneRange();
|
|
303
|
+
const form = this.root.querySelector(".k-rte__link");
|
|
304
|
+
form.hidden = false;
|
|
305
|
+
const input = form.querySelector("input");
|
|
306
|
+
input.value = "https://";
|
|
307
|
+
input.focus();
|
|
308
|
+
input.select();
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
emitChange(fire = true) {
|
|
314
|
+
const raw = this.area.innerHTML;
|
|
315
|
+
const out = sanitizeRichText(raw === "<p><br></p>" || raw === "<br>" ? "" : raw);
|
|
316
|
+
const changed = out !== this.html;
|
|
317
|
+
this.html = out;
|
|
318
|
+
this.paintFoot();
|
|
319
|
+
if (fire && changed)
|
|
320
|
+
emit(this, "kashi-change", { value: out, text: this.text });
|
|
321
|
+
}
|
|
322
|
+
paintFoot() {
|
|
323
|
+
const R = msg().richText;
|
|
324
|
+
const text = this.area.innerText ?? this.area.textContent ?? "";
|
|
325
|
+
const words = text.trim() ? text.trim().split(/\s+/).length : 0;
|
|
326
|
+
const foot = this.root.querySelector(".k-rte__foot");
|
|
327
|
+
foot.hidden = this.getAttribute("show-count") === "false";
|
|
328
|
+
foot.innerHTML = `<span>${esc(R.words(num(this, words)))}</span><span aria-hidden="true">·</span><span>${esc(R.chars(num(this, text.replace(/\n/g, "").length)))}</span><span class="k-rte__tip">${esc(R.zwnj)}</span>`;
|
|
329
|
+
const empty = !text.trim() && !/<(img|li|blockquote)/.test(this.html);
|
|
330
|
+
this.area.toggleAttribute("data-empty", empty);
|
|
331
|
+
syncHidden(this, this.getAttribute("name"), this.html);
|
|
332
|
+
}
|
|
333
|
+
update() {
|
|
334
|
+
const R = msg().richText;
|
|
335
|
+
const root = this.root;
|
|
336
|
+
const error = this.getAttribute("error"), hint = this.getAttribute("hint");
|
|
337
|
+
const disabled = this.hasAttribute("disabled");
|
|
338
|
+
const label = this.getAttribute("label");
|
|
339
|
+
root.className = "k-rte";
|
|
340
|
+
root.toggleAttribute("data-disabled", disabled);
|
|
341
|
+
root.toggleAttribute("data-invalid", !!error);
|
|
342
|
+
const l = root.querySelector(".k-rte__label");
|
|
343
|
+
l.textContent = label ?? "";
|
|
344
|
+
l.hidden = !label;
|
|
345
|
+
this.bar.setAttribute("aria-label", R.toolbar);
|
|
346
|
+
const a = this.area;
|
|
347
|
+
if (label) {
|
|
348
|
+
a.setAttribute("aria-labelledby", `${this.key}-label`);
|
|
349
|
+
a.removeAttribute("aria-label");
|
|
350
|
+
}
|
|
351
|
+
else {
|
|
352
|
+
a.removeAttribute("aria-labelledby");
|
|
353
|
+
a.setAttribute("aria-label", this.getAttribute("aria-label") ?? R.label);
|
|
354
|
+
}
|
|
355
|
+
if (error)
|
|
356
|
+
a.setAttribute("aria-invalid", "true");
|
|
357
|
+
else
|
|
358
|
+
a.removeAttribute("aria-invalid");
|
|
359
|
+
if (disabled)
|
|
360
|
+
a.setAttribute("aria-disabled", "true");
|
|
361
|
+
else
|
|
362
|
+
a.removeAttribute("aria-disabled");
|
|
363
|
+
a.contentEditable = disabled ? "false" : "true";
|
|
364
|
+
a.dataset.placeholder = this.getAttribute("placeholder") ?? R.placeholder;
|
|
365
|
+
a.style.minBlockSize = this.getAttribute("min-height") ?? "8rem";
|
|
366
|
+
const form = root.querySelector(".k-rte__link");
|
|
367
|
+
form.querySelector("input").setAttribute("aria-label", R.linkUrl);
|
|
368
|
+
form.querySelector("button").textContent = R.apply;
|
|
369
|
+
root.querySelector(".k-rte__help").innerHTML = error ? `<p class="k-hint k-hint--error">${esc(error)}</p>` : hint ? `<p class="k-hint">${esc(hint)}</p>` : `<span class="k-sr-only">${esc(R.zwnj)}</span>`;
|
|
370
|
+
this.paintTools();
|
|
371
|
+
this.paintFoot();
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
KashiRichText.observedAttributes = ["label", "aria-label", "placeholder", "tools", "min-height", "show-count", "name", "hint", "error", "disabled", "value"];
|
|
375
|
+
define("kashi-rich-text", KashiRichText, "block");
|
package/dist/sheets.d.ts
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { HTMLBase } from "./base.js";
|
|
2
|
+
/**
|
|
3
|
+
* پایهٔ پنجرههای روی <dialog> بومی: open، show() و close()، Esc، کلیک روی پسزمینه (dismissible)،
|
|
4
|
+
* انیمیشن خروج و برگشت فوکوس به دکمهای که پنجره را باز کرده بود.
|
|
5
|
+
*/
|
|
6
|
+
declare abstract class Modal extends HTMLBase {
|
|
7
|
+
protected dialog: HTMLDialogElement | null;
|
|
8
|
+
private opener;
|
|
9
|
+
protected key: string;
|
|
10
|
+
connectedCallback(): void;
|
|
11
|
+
attributeChangedCallback(n: string, old: string | null, next: string | null): void;
|
|
12
|
+
get open(): boolean;
|
|
13
|
+
set open(v: boolean);
|
|
14
|
+
show(): void;
|
|
15
|
+
close(returnValue?: string): void;
|
|
16
|
+
/** ساختار داخل <dialog>؛ بدنه و پاورقی */
|
|
17
|
+
protected abstract build(d: HTMLDialogElement, body: Node[], footer: Element[]): void;
|
|
18
|
+
protected abstract decorate(): void;
|
|
19
|
+
private setup;
|
|
20
|
+
protected heading(extra?: string): string;
|
|
21
|
+
protected closeButton(): string;
|
|
22
|
+
protected texts(): void;
|
|
23
|
+
protected wrap(cls: string, nodes: Node[]): HTMLDivElement;
|
|
24
|
+
protected sync(): void;
|
|
25
|
+
protected opened(): void;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* کشوی کناری روی <dialog> بومی برای فیلترها، جزئیات یا منوی گوشی: heading، description، side (start یا end)، size و dismissible.
|
|
29
|
+
* محتوای خود عنصر بدنه است و slot="footer" دکمههای پایین. دکمه با data-kashi-open="شناسه" بازش میکند.
|
|
30
|
+
*/
|
|
31
|
+
export declare class KashiDrawer extends Modal {
|
|
32
|
+
static observedAttributes: string[];
|
|
33
|
+
protected build(d: HTMLDialogElement, body: Node[], footer: Element[]): void;
|
|
34
|
+
protected decorate(): void;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* برگهٔ پایین برای گوشی: با دستگیره کشیده میشود و روی snap-points (مثل "0.5, 0.9" از ارتفاع صفحه) میایستد؛
|
|
38
|
+
* کشیدن به پایین یا Esc میبندد. دستگیره با کیبورد: Enter ایست بعدی، ↑↓ تغییر ارتفاع. hide-title و show-close.
|
|
39
|
+
*/
|
|
40
|
+
export declare class KashiBottomSheet extends Modal {
|
|
41
|
+
static observedAttributes: string[];
|
|
42
|
+
private current;
|
|
43
|
+
private drag;
|
|
44
|
+
/** ایست فعلی (اندیس snap-points) */
|
|
45
|
+
get snap(): number;
|
|
46
|
+
set snap(i: number);
|
|
47
|
+
private get points();
|
|
48
|
+
protected build(d: HTMLDialogElement, body: Node[], footer: Element[]): void;
|
|
49
|
+
protected decorate(): void;
|
|
50
|
+
protected opened(): void;
|
|
51
|
+
private paintSnap;
|
|
52
|
+
private setSnap;
|
|
53
|
+
private down;
|
|
54
|
+
private move;
|
|
55
|
+
private up;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* نوار ناوبری بالای سایت: slot="brand" لوگو، فرزندان <a> پیوندها (aria-current="page" صفحهٔ فعلی، data-badge نشان)،
|
|
59
|
+
* slot="actions" دکمهها و slot="menu-footer" پایین منوی گوشی. زیر collapse-below پیوندها به کشوی منو میروند.
|
|
60
|
+
*/
|
|
61
|
+
export declare class KashiNavbar extends HTMLBase {
|
|
62
|
+
static observedAttributes: string[];
|
|
63
|
+
private header;
|
|
64
|
+
private nav;
|
|
65
|
+
private drawer;
|
|
66
|
+
private ro;
|
|
67
|
+
connectedCallback(): void;
|
|
68
|
+
disconnectedCallback(): void;
|
|
69
|
+
attributeChangedCallback(): void;
|
|
70
|
+
private onScroll;
|
|
71
|
+
private build;
|
|
72
|
+
private place;
|
|
73
|
+
private toCurrent;
|
|
74
|
+
private update;
|
|
75
|
+
}
|
|
76
|
+
export interface NotificationItem {
|
|
77
|
+
id: string;
|
|
78
|
+
title: string;
|
|
79
|
+
body?: string;
|
|
80
|
+
/** زمان ISO */
|
|
81
|
+
time: string;
|
|
82
|
+
read?: boolean;
|
|
83
|
+
tone?: "brand" | "success" | "warning" | "error";
|
|
84
|
+
/** پیوند اعلان */
|
|
85
|
+
href?: string;
|
|
86
|
+
/** نشانی تصویر کوچک (آواتار) سمت شروع */
|
|
87
|
+
image?: string;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* فهرست اعلانها با زبانههای «همه» و «خواندهنشده»، گروه امروز و دیروز و زمان نسبی؛ داده با items (JSON یا JavaScript).
|
|
91
|
+
* کلیک یا دکمهٔ نقطه اعلان را خوانده میکند (kashi-read)؛ kashi-select برای اعلان بدون href.
|
|
92
|
+
*/
|
|
93
|
+
export declare class KashiNotificationList extends HTMLBase {
|
|
94
|
+
static observedAttributes: string[];
|
|
95
|
+
protected data: NotificationItem[] | null;
|
|
96
|
+
private tab;
|
|
97
|
+
protected root: HTMLDivElement | null;
|
|
98
|
+
connectedCallback(): void;
|
|
99
|
+
attributeChangedCallback(n: string, old: string | null, next: string | null): void;
|
|
100
|
+
protected mount(root: HTMLElement): void;
|
|
101
|
+
get items(): NotificationItem[];
|
|
102
|
+
set items(v: NotificationItem[]);
|
|
103
|
+
/** تعداد اعلانهای خواندهنشده */
|
|
104
|
+
get unread(): number;
|
|
105
|
+
/** خوانده کردن یک اعلان */
|
|
106
|
+
markRead(id: string): void;
|
|
107
|
+
markAllRead(): void;
|
|
108
|
+
private onClick;
|
|
109
|
+
protected render(): void;
|
|
110
|
+
protected rendered(_unread: number): void;
|
|
111
|
+
}
|
|
112
|
+
/** دکمهٔ زنگ با شمار خواندهنشدهها که فهرست اعلانها را در پاپاور باز میکند؛ همان ویژگیهای kashi-notification-list بهاضافهٔ placement */
|
|
113
|
+
export declare class KashiNotificationCenter extends KashiNotificationList {
|
|
114
|
+
static observedAttributes: string[];
|
|
115
|
+
private bell;
|
|
116
|
+
private panel;
|
|
117
|
+
private last;
|
|
118
|
+
private key;
|
|
119
|
+
protected mount(root: HTMLElement): void;
|
|
120
|
+
disconnectedCallback(): void;
|
|
121
|
+
get open(): boolean;
|
|
122
|
+
set open(v: boolean);
|
|
123
|
+
show(): void;
|
|
124
|
+
close(focus?: boolean): void;
|
|
125
|
+
private onOutside;
|
|
126
|
+
protected rendered(unread: number): void;
|
|
127
|
+
}
|
|
128
|
+
export {};
|