@x-plat/design-system 0.20.0 → 0.21.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/dist/chunk-2EGVOUGV.cjs +93 -0
- package/dist/chunk-2T3BVV7R.js +0 -0
- package/dist/chunk-3FYYFDKQ.js +159 -0
- package/dist/chunk-3M3GFSHJ.js +67 -0
- package/dist/chunk-3WBHUFOA.cjs +48 -0
- package/dist/chunk-3XYYZQR5.cjs +22 -0
- package/dist/chunk-4EF7NVAL.js +67 -0
- package/dist/chunk-4ISERXK2.cjs +1 -0
- package/dist/chunk-4KYHHJ6Z.cjs +250 -0
- package/dist/chunk-4NSRDRXC.cjs +70 -0
- package/dist/chunk-4OXMRSVE.cjs +99 -0
- package/dist/chunk-55EPYLXN.js +30 -0
- package/dist/chunk-5CE3ADO5.js +254 -0
- package/dist/chunk-5F6Y2JD6.cjs +1 -0
- package/dist/chunk-5FMTMXSP.cjs +127 -0
- package/dist/chunk-5POCKDDY.js +36 -0
- package/dist/chunk-5VDI56BV.js +33 -0
- package/dist/chunk-5WLBUPSK.js +77 -0
- package/dist/chunk-5WNNWQHD.cjs +272 -0
- package/dist/chunk-66STZB6I.cjs +404 -0
- package/dist/chunk-6AIKCZN7.js +1455 -0
- package/dist/chunk-6IUJJUVP.js +18 -0
- package/dist/chunk-6P2B3ZGP.js +79 -0
- package/dist/chunk-764ILIDG.cjs +22 -0
- package/dist/chunk-7B44DWC4.js +0 -0
- package/dist/chunk-7BE6ETFY.js +18 -0
- package/dist/chunk-7BSUS5A4.js +97 -0
- package/dist/chunk-7RPWCDEW.cjs +20 -0
- package/dist/chunk-7ULXHGLO.cjs +77 -0
- package/dist/chunk-7YOI5XOW.js +55 -0
- package/dist/chunk-AFVTM5CP.js +0 -0
- package/dist/chunk-AN2WSL3B.cjs +1 -0
- package/dist/chunk-AT5Y5GLS.cjs +118 -0
- package/dist/chunk-AWPO2FI7.js +404 -0
- package/dist/chunk-BGXHIDUR.js +103 -0
- package/dist/chunk-BPZXL5TP.js +99 -0
- package/dist/chunk-BRTS5GWV.js +275 -0
- package/dist/chunk-BS3MLZCK.cjs +97 -0
- package/dist/chunk-BSPYYE2U.js +36 -0
- package/dist/chunk-BWJAEB42.js +48 -0
- package/dist/chunk-C4RMTISI.cjs +18 -0
- package/dist/chunk-C6M4XVR7.cjs +36 -0
- package/dist/chunk-CGC4D5MP.cjs +89 -0
- package/dist/chunk-CIRQYSQW.js +70 -0
- package/dist/chunk-CLOTWJNP.cjs +310 -0
- package/dist/chunk-CS7ZY35M.cjs +49 -0
- package/dist/chunk-CUV4RLDE.js +89 -0
- package/dist/chunk-CZAMLFSE.cjs +275 -0
- package/dist/chunk-D7QZLJ3Z.cjs +18 -0
- package/dist/chunk-DMSAAZ3M.cjs +92 -0
- package/dist/chunk-DUIZC7VJ.cjs +36 -0
- package/dist/chunk-DVBF4BDH.js +43 -0
- package/dist/chunk-EETYMP6K.cjs +584 -0
- package/dist/chunk-EFQL7JPX.js +0 -0
- package/dist/chunk-EFU7IAF5.cjs +12 -0
- package/dist/chunk-F3M2H5EX.cjs +79 -0
- package/dist/chunk-F436V2SX.cjs +254 -0
- package/dist/chunk-F664X2OY.js +250 -0
- package/dist/chunk-FF7ELUQW.cjs +1 -0
- package/dist/chunk-G3HE4S3Q.cjs +296 -0
- package/dist/chunk-GOPD5KUK.js +23 -0
- package/dist/chunk-GYTB24V6.cjs +107 -0
- package/dist/chunk-GZ657SGO.js +310 -0
- package/dist/chunk-H2QN65L6.cjs +1 -0
- package/dist/chunk-H6WUT7CK.js +22 -0
- package/dist/chunk-H76OQ75T.js +49 -0
- package/dist/chunk-HA3XONYI.js +18 -0
- package/dist/chunk-HF3UFXEU.js +296 -0
- package/dist/chunk-HGA47QVV.cjs +55 -0
- package/dist/chunk-HHPPAMXF.cjs +674 -0
- package/dist/chunk-HLV2XIE2.cjs +385 -0
- package/dist/chunk-HNQGIL45.cjs +96 -0
- package/dist/chunk-HQ37R7T3.js +53 -0
- package/dist/chunk-HXUGW4RR.js +187 -0
- package/dist/chunk-HYPRLWD3.js +272 -0
- package/dist/chunk-I7TLJUTP.cjs +6 -0
- package/dist/chunk-ICTWDTKC.cjs +1 -0
- package/dist/chunk-IPYKHDP4.cjs +187 -0
- package/dist/chunk-IRKREQ2X.cjs +18 -0
- package/dist/chunk-IVJJBMRY.js +92 -0
- package/dist/chunk-JPVIVOFG.js +26 -0
- package/dist/chunk-JYNBNSNF.js +151 -0
- package/dist/chunk-JZC3BXAC.js +93 -0
- package/dist/chunk-K5XPQWXN.cjs +92 -0
- package/dist/chunk-KQ3GOMHL.js +31 -0
- package/dist/chunk-KUJH72U6.cjs +159 -0
- package/dist/chunk-KVUXLC6M.cjs +479 -0
- package/dist/chunk-KZOJN57Q.js +19 -0
- package/dist/chunk-L3XPL4NP.cjs +53 -0
- package/dist/chunk-LOEMSXYB.js +0 -0
- package/dist/chunk-LU4KBPNG.cjs +23 -0
- package/dist/chunk-MWWWPQDB.js +26 -0
- package/dist/chunk-NCBB3WUJ.js +562 -0
- package/dist/chunk-NGCZTZST.cjs +562 -0
- package/dist/chunk-NSDKALIS.cjs +67 -0
- package/dist/chunk-NZHCRLNB.cjs +26 -0
- package/dist/chunk-OL4NANHB.js +0 -0
- package/dist/chunk-OTJRNKLR.js +96 -0
- package/dist/chunk-OWWFKTSK.js +0 -0
- package/dist/chunk-P2E3PB62.cjs +99 -0
- package/dist/chunk-P2QVFR7S.js +20 -0
- package/dist/chunk-P6ZGIYY7.cjs +18 -0
- package/dist/chunk-PFGSJJRY.cjs +19 -0
- package/dist/chunk-PNIUW7AJ.cjs +32 -0
- package/dist/chunk-Q2M2ONGO.js +70 -0
- package/dist/chunk-Q4PGP5KE.cjs +562 -0
- package/dist/chunk-QAI2YQPY.cjs +51 -0
- package/dist/chunk-QCD7UEZ3.cjs +59 -0
- package/dist/chunk-QEZ4R3SK.js +6 -0
- package/dist/chunk-QKDCPM2D.cjs +23 -0
- package/dist/chunk-QRGG3V7W.cjs +59 -0
- package/dist/chunk-QURIHUEC.js +107 -0
- package/dist/chunk-QY742LWN.js +30 -0
- package/dist/chunk-QYMRGYTN.js +127 -0
- package/dist/chunk-RLKJ2RZG.js +23 -0
- package/dist/chunk-RRR5BUOM.cjs +30 -0
- package/dist/chunk-RU3FCVXM.cjs +1 -0
- package/dist/chunk-RYTDVTV2.js +32 -0
- package/dist/chunk-RYYGUYDE.js +92 -0
- package/dist/chunk-SGLP4U3Y.cjs +67 -0
- package/dist/chunk-SJC543ZK.js +71 -0
- package/dist/chunk-SLYQK4SC.js +20 -0
- package/dist/chunk-SMLCOMLS.js +2888 -0
- package/dist/chunk-SNMOPLMH.cjs +372 -0
- package/dist/chunk-TRJUJYW7.cjs +151 -0
- package/dist/chunk-TTY5PE3P.js +30 -0
- package/dist/chunk-TXARYG3J.js +22 -0
- package/dist/chunk-TYXJU4EF.js +18 -0
- package/dist/chunk-U3PC7FYZ.cjs +26 -0
- package/dist/chunk-U67JM2WL.cjs +34 -0
- package/dist/chunk-UARGO5UG.js +59 -0
- package/dist/chunk-UCYE3H3F.cjs +43 -0
- package/dist/chunk-UGEGN35F.js +118 -0
- package/dist/chunk-UHUA3GQC.cjs +30 -0
- package/dist/chunk-UJQN477L.js +59 -0
- package/dist/chunk-UMX7DTFZ.cjs +70 -0
- package/dist/chunk-UT42P54P.js +372 -0
- package/dist/chunk-V76ZRGHQ.cjs +1 -0
- package/dist/chunk-VCIK366Y.cjs +1455 -0
- package/dist/chunk-VMA74ABT.cjs +137 -0
- package/dist/chunk-VSA62N2O.js +12 -0
- package/dist/chunk-WDAFLVQK.js +479 -0
- package/dist/chunk-WHMLMAMO.js +674 -0
- package/dist/chunk-WNBLKKLM.js +0 -0
- package/dist/chunk-WQ2GY7F3.js +46 -0
- package/dist/chunk-WRLCCK3M.cjs +30 -0
- package/dist/chunk-WVCZIOLY.js +562 -0
- package/dist/chunk-WZLGJQLW.js +385 -0
- package/dist/chunk-XB6FEBK6.js +34 -0
- package/dist/chunk-XMERDSRE.js +75 -0
- package/dist/chunk-XMLFKZYY.js +137 -0
- package/dist/chunk-XMM52J3T.js +584 -0
- package/dist/chunk-XZ7C5CGB.cjs +103 -0
- package/dist/chunk-YGFBAOKX.js +51 -0
- package/dist/chunk-YIN552MF.cjs +20 -0
- package/dist/chunk-YLC42E65.cjs +31 -0
- package/dist/chunk-YOTXRYJL.cjs +46 -0
- package/dist/chunk-ZAUGJZK7.js +99 -0
- package/dist/chunk-ZIZOQTDG.cjs +75 -0
- package/dist/chunk-ZMSV5VZI.cjs +2888 -0
- package/dist/chunk-ZN6MLZAE.cjs +71 -0
- package/dist/chunk-ZNCT6HXA.cjs +33 -0
- package/dist/components/Accordion/index.cjs +5 -1036
- package/dist/components/Accordion/index.js +5 -999
- package/dist/components/Alert/index.cjs +4 -69
- package/dist/components/Alert/index.js +4 -42
- package/dist/components/AutoResizeTextArea/index.cjs +6 -260
- package/dist/components/AutoResizeTextArea/index.js +6 -223
- package/dist/components/Avatar/index.cjs +4 -65
- package/dist/components/Avatar/index.js +4 -38
- package/dist/components/Badge/index.cjs +6 -69
- package/dist/components/Badge/index.js +5 -40
- package/dist/components/Box/index.cjs +4 -58
- package/dist/components/Box/index.js +4 -31
- package/dist/components/Breadcrumb/index.cjs +4 -42
- package/dist/components/Breadcrumb/index.js +3 -14
- package/dist/components/Button/index.cjs +5 -65
- package/dist/components/Button/index.js +5 -38
- package/dist/components/Calendar/index.cjs +6 -1317
- package/dist/components/Calendar/index.js +10 -1281
- package/dist/components/CardTab/index.cjs +4 -120
- package/dist/components/CardTab/index.js +4 -83
- package/dist/components/Chart/index.cjs +5 -708
- package/dist/components/Chart/index.js +4 -670
- package/dist/components/ChatInput/index.cjs +9 -390
- package/dist/components/ChatInput/index.js +9 -353
- package/dist/components/CheckBox/index.cjs +20 -1125
- package/dist/components/CheckBox/index.js +17 -1095
- package/dist/components/Chip/index.cjs +5 -55
- package/dist/components/Chip/index.js +5 -28
- package/dist/components/DatePicker/index.cjs +16 -2136
- package/dist/components/DatePicker/index.js +19 -2099
- package/dist/components/Divider/index.cjs +4 -58
- package/dist/components/Divider/index.js +4 -31
- package/dist/components/Drawer/index.cjs +5 -190
- package/dist/components/Drawer/index.js +5 -153
- package/dist/components/Dropdown/index.cjs +7 -375
- package/dist/components/Dropdown/index.js +7 -338
- package/dist/components/Editor/index.cjs +6 -1486
- package/dist/components/Editor/index.css +53 -0
- package/dist/components/Editor/index.d.cts +13 -0
- package/dist/components/Editor/index.d.ts +13 -0
- package/dist/components/Editor/index.js +6 -1453
- package/dist/components/EmptyState/index.cjs +4 -42
- package/dist/components/EmptyState/index.js +3 -14
- package/dist/components/FieldMessage/index.cjs +7 -182
- package/dist/components/FieldMessage/index.js +8 -154
- package/dist/components/FileUpload/index.cjs +7 -1171
- package/dist/components/FileUpload/index.js +7 -1134
- package/dist/components/HtmlTypeWriter/index.cjs +3 -171
- package/dist/components/HtmlTypeWriter/index.js +3 -133
- package/dist/components/IconButton/index.cjs +4 -65
- package/dist/components/IconButton/index.js +4 -38
- package/dist/components/ImageSelector/index.cjs +8 -1214
- package/dist/components/ImageSelector/index.js +8 -1177
- package/dist/components/Input/index.cjs +7 -429
- package/dist/components/Input/index.js +8 -392
- package/dist/components/Link/index.cjs +4 -61
- package/dist/components/Link/index.js +4 -34
- package/dist/components/LinkButton/index.cjs +5 -61
- package/dist/components/LinkButton/index.js +5 -34
- package/dist/components/Modal/index.cjs +5 -190
- package/dist/components/Modal/index.js +5 -153
- package/dist/components/NotificationBadge/index.cjs +5 -68
- package/dist/components/NotificationBadge/index.js +5 -40
- package/dist/components/Pagination/index.cjs +6 -1034
- package/dist/components/Pagination/index.js +6 -1007
- package/dist/components/PopOver/index.cjs +7 -363
- package/dist/components/PopOver/index.js +7 -326
- package/dist/components/Progress/index.cjs +5 -84
- package/dist/components/Progress/index.js +5 -57
- package/dist/components/Radio/index.cjs +7 -274
- package/dist/components/Radio/index.js +8 -237
- package/dist/components/Select/index.cjs +10 -1577
- package/dist/components/Select/index.js +11 -1540
- package/dist/components/Skeleton/index.cjs +4 -71
- package/dist/components/Skeleton/index.js +4 -44
- package/dist/components/Spinner/index.cjs +5 -88
- package/dist/components/Spinner/index.js +5 -61
- package/dist/components/Stat/index.cjs +5 -81
- package/dist/components/Stat/index.js +5 -54
- package/dist/components/Steps/index.cjs +7 -968
- package/dist/components/Steps/index.js +7 -941
- package/dist/components/Swiper/index.cjs +4 -357
- package/dist/components/Swiper/index.js +4 -320
- package/dist/components/Switch/index.cjs +7 -252
- package/dist/components/Switch/index.js +7 -215
- package/dist/components/Tab/index.cjs +4 -144
- package/dist/components/Tab/index.js +4 -107
- package/dist/components/Table/index.cjs +4 -337
- package/dist/components/Table/index.js +8 -300
- package/dist/components/Tag/index.cjs +6 -969
- package/dist/components/Tag/index.js +6 -942
- package/dist/components/TextArea/index.cjs +6 -229
- package/dist/components/TextArea/index.js +6 -192
- package/dist/components/TimePicker/index.cjs +9 -579
- package/dist/components/TimePicker/index.js +9 -542
- package/dist/components/Toast/index.cjs +5 -146
- package/dist/components/Toast/index.js +5 -108
- package/dist/components/ToggleChip/index.cjs +5 -66
- package/dist/components/ToggleChip/index.js +5 -39
- package/dist/components/Tooltip/index.cjs +6 -204
- package/dist/components/Tooltip/index.js +6 -167
- package/dist/components/Tour/index.cjs +6 -414
- package/dist/components/Tour/index.js +6 -377
- package/dist/components/Video/index.cjs +7 -796
- package/dist/components/Video/index.js +7 -759
- package/dist/components/index.cjs +140 -8342
- package/dist/components/index.js +190 -8288
- package/dist/index.cjs +903 -13318
- package/dist/index.js +524 -12526
- package/dist/layout/Grid/FullGrid/index.cjs +4 -46
- package/dist/layout/Grid/FullGrid/index.js +3 -18
- package/dist/layout/Grid/FullScreen/index.cjs +4 -46
- package/dist/layout/Grid/FullScreen/index.js +3 -18
- package/dist/layout/Grid/Item/index.cjs +5 -68
- package/dist/layout/Grid/Item/index.js +5 -41
- package/dist/layout/Grid/index.cjs +14 -109
- package/dist/layout/Grid/index.js +14 -79
- package/dist/layout/Header/index.cjs +4 -44
- package/dist/layout/Header/index.js +3 -16
- package/dist/layout/Layout/index.cjs +4 -42
- package/dist/layout/Layout/index.js +3 -14
- package/dist/layout/SideBar/index.cjs +6 -96
- package/dist/layout/SideBar/index.js +6 -57
- package/dist/layout/index.cjs +38 -209
- package/dist/layout/index.js +27 -153
- package/dist/tokens/index.cjs +627 -6119
- package/dist/tokens/index.js +324 -5489
- package/guidelines/components/editor.md +3 -0
- package/guidelines/setup.md +7 -0
- package/package.json +6 -3
|
@@ -1,1456 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
if ("string" == typeof e || "number" == typeof e) n += e;
|
|
8
|
-
else if ("object" == typeof e) if (Array.isArray(e)) {
|
|
9
|
-
var o = e.length;
|
|
10
|
-
for (t = 0; t < o; t++) e[t] && (f = r(e[t])) && (n && (n += " "), n += f);
|
|
11
|
-
} else for (f in e) e[f] && (n && (n += " "), n += f);
|
|
12
|
-
return n;
|
|
13
|
-
}
|
|
14
|
-
function clsx() {
|
|
15
|
-
for (var e, t, f = 0, n = "", o = arguments.length; f < o; f++) (e = arguments[f]) && (t = r(e)) && (n && (n += " "), n += t);
|
|
16
|
-
return n;
|
|
17
|
-
}
|
|
18
|
-
var clsx_default = clsx;
|
|
19
|
-
|
|
20
|
-
// src/components/Editor/highlight.ts
|
|
21
|
-
var CODE_LANGUAGES = [
|
|
22
|
-
{ value: "plain", label: "\uC5C6\uC74C" },
|
|
23
|
-
{ value: "javascript", label: "JavaScript" },
|
|
24
|
-
{ value: "typescript", label: "TypeScript" },
|
|
25
|
-
{ value: "json", label: "JSON" },
|
|
26
|
-
{ value: "html", label: "HTML" },
|
|
27
|
-
{ value: "css", label: "CSS" },
|
|
28
|
-
{ value: "python", label: "Python" },
|
|
29
|
-
{ value: "sql", label: "SQL" },
|
|
30
|
-
{ value: "bash", label: "Bash" }
|
|
31
|
-
];
|
|
32
|
-
var KEYWORDS = {
|
|
33
|
-
plain: [],
|
|
34
|
-
javascript: "const let var function return if else for while class new this import export from default async await try catch throw typeof instanceof null undefined true false break continue switch case do delete in of yield".split(" "),
|
|
35
|
-
typescript: "const let var function return if else for while class new this import export from default async await try catch throw typeof instanceof null undefined true false break continue switch case do delete in of yield interface type enum implements extends public private protected readonly as satisfies keyof infer never unknown any".split(" "),
|
|
36
|
-
json: ["true", "false", "null"],
|
|
37
|
-
html: [],
|
|
38
|
-
css: [],
|
|
39
|
-
python: "def class return if elif else for while import from as try except finally raise with lambda None True False and or not in is pass break continue global nonlocal yield async await".split(" "),
|
|
40
|
-
sql: "SELECT FROM WHERE INSERT INTO VALUES UPDATE SET DELETE CREATE TABLE ALTER DROP JOIN LEFT RIGHT INNER OUTER ON GROUP BY ORDER HAVING LIMIT OFFSET AS AND OR NOT NULL DISTINCT UNION INDEX PRIMARY KEY FOREIGN REFERENCES DEFAULT".split(" "),
|
|
41
|
-
bash: "if then else fi for while do done case esac function return export local echo cd ls rm cp mv mkdir sudo source set unset exit".split(" ")
|
|
42
|
-
};
|
|
43
|
-
var LINE_COMMENT = {
|
|
44
|
-
javascript: "//",
|
|
45
|
-
typescript: "//",
|
|
46
|
-
css: "",
|
|
47
|
-
python: "#",
|
|
48
|
-
sql: "--",
|
|
49
|
-
bash: "#"
|
|
50
|
-
};
|
|
51
|
-
var escape = (s) => s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
52
|
-
var wrap = (cls, text) => `<span class="tok-${cls}">${escape(text)}</span>`;
|
|
53
|
-
var highlight = (code, lang) => {
|
|
54
|
-
if (lang === "plain" || !code) return escape(code);
|
|
55
|
-
const keywords = new Set(KEYWORDS[lang]);
|
|
56
|
-
const lineComment = LINE_COMMENT[lang];
|
|
57
|
-
const caseInsensitive = lang === "sql";
|
|
58
|
-
let out = "";
|
|
59
|
-
let i = 0;
|
|
60
|
-
while (i < code.length) {
|
|
61
|
-
const rest = code.slice(i);
|
|
62
|
-
if ((lang === "javascript" || lang === "typescript" || lang === "css") && rest.startsWith("/*")) {
|
|
63
|
-
const end = code.indexOf("*/", i + 2);
|
|
64
|
-
const stop = end === -1 ? code.length : end + 2;
|
|
65
|
-
out += wrap("comment", code.slice(i, stop));
|
|
66
|
-
i = stop;
|
|
67
|
-
continue;
|
|
68
|
-
}
|
|
69
|
-
if (lineComment && rest.startsWith(lineComment)) {
|
|
70
|
-
const nl = code.indexOf("\n", i);
|
|
71
|
-
const stop = nl === -1 ? code.length : nl;
|
|
72
|
-
out += wrap("comment", code.slice(i, stop));
|
|
73
|
-
i = stop;
|
|
74
|
-
continue;
|
|
75
|
-
}
|
|
76
|
-
const q = rest[0];
|
|
77
|
-
if (q === '"' || q === "'" || q === "`") {
|
|
78
|
-
let j = 1;
|
|
79
|
-
while (j < rest.length) {
|
|
80
|
-
if (rest[j] === "\\") {
|
|
81
|
-
j += 2;
|
|
82
|
-
continue;
|
|
83
|
-
}
|
|
84
|
-
if (rest[j] === q) {
|
|
85
|
-
j += 1;
|
|
86
|
-
break;
|
|
87
|
-
}
|
|
88
|
-
if (rest[j] === "\n" && q !== "`") break;
|
|
89
|
-
j += 1;
|
|
90
|
-
}
|
|
91
|
-
out += wrap("string", rest.slice(0, j));
|
|
92
|
-
i += j;
|
|
93
|
-
continue;
|
|
94
|
-
}
|
|
95
|
-
const num = /^\d+(\.\d+)?/.exec(rest);
|
|
96
|
-
if (num && !/[\w$]/.test(code[i - 1] ?? "")) {
|
|
97
|
-
out += wrap("number", num[0]);
|
|
98
|
-
i += num[0].length;
|
|
99
|
-
continue;
|
|
100
|
-
}
|
|
101
|
-
const word = /^[A-Za-z_$][\w$]*/.exec(rest);
|
|
102
|
-
if (word) {
|
|
103
|
-
const w = word[0];
|
|
104
|
-
const hit = caseInsensitive ? keywords.has(w.toUpperCase()) : keywords.has(w);
|
|
105
|
-
out += hit ? wrap("keyword", w) : escape(w);
|
|
106
|
-
i += w.length;
|
|
107
|
-
continue;
|
|
108
|
-
}
|
|
109
|
-
if (lang === "html" && rest.startsWith("<")) {
|
|
110
|
-
const tag = /^<\/?[A-Za-z][\w-]*/.exec(rest);
|
|
111
|
-
if (tag) {
|
|
112
|
-
out += wrap("keyword", tag[0]);
|
|
113
|
-
i += tag[0].length;
|
|
114
|
-
continue;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
out += escape(code[i]);
|
|
118
|
-
i += 1;
|
|
119
|
-
}
|
|
120
|
-
return out;
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
// src/components/Editor/Editor.tsx
|
|
124
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
125
|
-
var DEFAULT_TOOLBAR = [
|
|
126
|
-
"bold",
|
|
127
|
-
"italic",
|
|
128
|
-
"underline",
|
|
129
|
-
"strikethrough",
|
|
130
|
-
"code",
|
|
131
|
-
"heading-1",
|
|
132
|
-
"heading-2",
|
|
133
|
-
"heading-3",
|
|
134
|
-
"list",
|
|
135
|
-
"ordered-list",
|
|
136
|
-
"blockquote",
|
|
137
|
-
"code-block",
|
|
138
|
-
"link",
|
|
139
|
-
"image",
|
|
140
|
-
"divider",
|
|
141
|
-
"checklist",
|
|
142
|
-
"table",
|
|
143
|
-
"align-left",
|
|
144
|
-
"align-center",
|
|
145
|
-
"align-right",
|
|
146
|
-
"highlight",
|
|
147
|
-
"superscript",
|
|
148
|
-
"subscript",
|
|
149
|
-
"clear-format",
|
|
150
|
-
"undo",
|
|
151
|
-
"redo"
|
|
152
|
-
];
|
|
153
|
-
var ALLOWED_TAGS = /* @__PURE__ */ new Set([
|
|
154
|
-
"p",
|
|
155
|
-
"br",
|
|
156
|
-
"h1",
|
|
157
|
-
"h2",
|
|
158
|
-
"h3",
|
|
159
|
-
"h4",
|
|
160
|
-
"h5",
|
|
161
|
-
"h6",
|
|
162
|
-
"ul",
|
|
163
|
-
"ol",
|
|
164
|
-
"li",
|
|
165
|
-
"blockquote",
|
|
166
|
-
"pre",
|
|
167
|
-
"code",
|
|
168
|
-
"strong",
|
|
169
|
-
"b",
|
|
170
|
-
"em",
|
|
171
|
-
"i",
|
|
172
|
-
"u",
|
|
173
|
-
"s",
|
|
174
|
-
"strike",
|
|
175
|
-
"del",
|
|
176
|
-
"a",
|
|
177
|
-
"img",
|
|
178
|
-
"hr",
|
|
179
|
-
"span",
|
|
180
|
-
"div",
|
|
181
|
-
"sub",
|
|
182
|
-
"sup",
|
|
183
|
-
"mark",
|
|
184
|
-
"table",
|
|
185
|
-
"thead",
|
|
186
|
-
"tbody",
|
|
187
|
-
"tr",
|
|
188
|
-
"th",
|
|
189
|
-
"td"
|
|
190
|
-
]);
|
|
191
|
-
var ALLOWED_ATTRS = {
|
|
192
|
-
a: ["href", "target", "rel"],
|
|
193
|
-
img: ["src", "alt", "width"],
|
|
194
|
-
// 정렬·체크리스트는 클래스로만 표현한다. style 을 열면 붙여넣기로 아무 CSS 나 들어온다
|
|
195
|
-
p: ["class"],
|
|
196
|
-
h1: ["class"],
|
|
197
|
-
h2: ["class"],
|
|
198
|
-
h3: ["class"],
|
|
199
|
-
h4: ["class"],
|
|
200
|
-
h5: ["class"],
|
|
201
|
-
h6: ["class"],
|
|
202
|
-
ul: ["class"],
|
|
203
|
-
ol: ["class"],
|
|
204
|
-
li: ["class", "data-checked"],
|
|
205
|
-
blockquote: ["class"],
|
|
206
|
-
div: ["class"],
|
|
207
|
-
span: ["class"],
|
|
208
|
-
pre: ["class"],
|
|
209
|
-
code: ["class"],
|
|
210
|
-
mark: ["class"],
|
|
211
|
-
table: ["class"],
|
|
212
|
-
td: ["class"],
|
|
213
|
-
th: ["class"],
|
|
214
|
-
tr: ["class"]
|
|
215
|
-
};
|
|
216
|
-
var DROP_WITH_CONTENT = /* @__PURE__ */ new Set([
|
|
217
|
-
"script",
|
|
218
|
-
"style",
|
|
219
|
-
"noscript",
|
|
220
|
-
"iframe",
|
|
221
|
-
"object",
|
|
222
|
-
"embed",
|
|
223
|
-
"template"
|
|
224
|
-
]);
|
|
225
|
-
var sanitizeHtml = (input) => {
|
|
226
|
-
const doc = new DOMParser().parseFromString(`<div>${input}</div>`, "text/html");
|
|
227
|
-
const root = doc.body.firstElementChild;
|
|
228
|
-
if (!root) return "";
|
|
229
|
-
const walk = (node) => {
|
|
230
|
-
const children = Array.from(node.children);
|
|
231
|
-
for (const child of children) {
|
|
232
|
-
const tag = child.tagName.toLowerCase();
|
|
233
|
-
if (DROP_WITH_CONTENT.has(tag)) {
|
|
234
|
-
node.removeChild(child);
|
|
235
|
-
continue;
|
|
236
|
-
}
|
|
237
|
-
if (!ALLOWED_TAGS.has(tag)) {
|
|
238
|
-
while (child.firstChild) node.insertBefore(child.firstChild, child);
|
|
239
|
-
node.removeChild(child);
|
|
240
|
-
continue;
|
|
241
|
-
}
|
|
242
|
-
const allowed = ALLOWED_ATTRS[tag] || [];
|
|
243
|
-
for (const attr of Array.from(child.attributes)) {
|
|
244
|
-
if (!allowed.includes(attr.name)) {
|
|
245
|
-
child.removeAttribute(attr.name);
|
|
246
|
-
}
|
|
247
|
-
if (attr.name === "href" || attr.name === "src") {
|
|
248
|
-
const val = attr.value.trim().toLowerCase();
|
|
249
|
-
if (val.startsWith("javascript:") || val.startsWith("data:text/html")) {
|
|
250
|
-
child.removeAttribute(attr.name);
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
walk(child);
|
|
255
|
-
}
|
|
256
|
-
};
|
|
257
|
-
walk(root);
|
|
258
|
-
return root.innerHTML;
|
|
259
|
-
};
|
|
260
|
-
var escapeHtml = (text) => {
|
|
261
|
-
const div = document.createElement("div");
|
|
262
|
-
div.textContent = text;
|
|
263
|
-
return div.innerHTML.replace(/\n/g, "<br>");
|
|
264
|
-
};
|
|
265
|
-
var SLASH_ITEMS = [
|
|
266
|
-
{ key: "paragraph", label: "\uB2E8\uB77D", hint: "\uAE30\uBCF8 \uD14D\uC2A4\uD2B8" },
|
|
267
|
-
{ key: "heading-1", label: "\uC81C\uBAA9 1", hint: "\uAC00\uC7A5 \uD070 \uC81C\uBAA9" },
|
|
268
|
-
{ key: "heading-2", label: "\uC81C\uBAA9 2", hint: "" },
|
|
269
|
-
{ key: "heading-3", label: "\uC81C\uBAA9 3", hint: "" },
|
|
270
|
-
{ key: "list", label: "\uAE00\uBA38\uB9AC \uAE30\uD638 \uBAA9\uB85D", hint: "\u2022 \uD56D\uBAA9" },
|
|
271
|
-
{ key: "ordered-list", label: "\uBC88\uD638 \uB9E4\uAE30\uAE30 \uBAA9\uB85D", hint: "1. \uD56D\uBAA9" },
|
|
272
|
-
{ key: "blockquote", label: "\uC778\uC6A9", hint: "" },
|
|
273
|
-
{ key: "code-block", label: "\uCF54\uB4DC \uBE14\uB85D", hint: "" },
|
|
274
|
-
{ key: "divider", label: "\uAD6C\uBD84\uC120", hint: "\u2500" },
|
|
275
|
-
{ key: "image", label: "\uC774\uBBF8\uC9C0", hint: "" }
|
|
276
|
-
];
|
|
277
|
-
var Editor = (props) => {
|
|
278
|
-
const {
|
|
279
|
-
value = "",
|
|
280
|
-
onChange,
|
|
281
|
-
placeholder = "\uB0B4\uC6A9\uC744 \uC785\uB825\uD558\uC138\uC694",
|
|
282
|
-
readOnly = false,
|
|
283
|
-
toolbar = DEFAULT_TOOLBAR,
|
|
284
|
-
enableSlashCommand = true,
|
|
285
|
-
enableMarkdownShortcuts = true,
|
|
286
|
-
onImageUpload,
|
|
287
|
-
minHeight = 200
|
|
288
|
-
} = props;
|
|
289
|
-
const editorRef = React.useRef(null);
|
|
290
|
-
const lastRangeRef = React.useRef(null);
|
|
291
|
-
const composingRef = React.useRef(false);
|
|
292
|
-
const [isFocused, setIsFocused] = React.useState(false);
|
|
293
|
-
const [isEmpty, setIsEmpty] = React.useState(!value);
|
|
294
|
-
const [activeFormats, setActiveFormats] = React.useState(/* @__PURE__ */ new Set());
|
|
295
|
-
const [slashOpen, setSlashOpen] = React.useState(false);
|
|
296
|
-
const [slashFilter, setSlashFilter] = React.useState("");
|
|
297
|
-
const [slashIdx, setSlashIdx] = React.useState(0);
|
|
298
|
-
const [slashPos, setSlashPos] = React.useState({ top: 0, left: 0 });
|
|
299
|
-
const slashStartRangeRef = React.useRef(null);
|
|
300
|
-
const [linkOpen, setLinkOpen] = React.useState(false);
|
|
301
|
-
const [linkValue, setLinkValue] = React.useState("");
|
|
302
|
-
const [linkPos, setLinkPos] = React.useState({ top: 0, left: 0 });
|
|
303
|
-
const lastEmittedRef = React.useRef(null);
|
|
304
|
-
React.useEffect(() => {
|
|
305
|
-
const el = editorRef.current;
|
|
306
|
-
if (!el) return;
|
|
307
|
-
if (value === lastEmittedRef.current) return;
|
|
308
|
-
if (el.innerHTML === value) return;
|
|
309
|
-
el.innerHTML = sanitizeHtml(value || "");
|
|
310
|
-
if (!el.firstChild) el.innerHTML = "<p><br></p>";
|
|
311
|
-
lastEmittedRef.current = null;
|
|
312
|
-
historyRef.current = [{ html: el.innerHTML, caret: 0 }];
|
|
313
|
-
historyIdxRef.current = 0;
|
|
314
|
-
updateEmpty();
|
|
315
|
-
}, [value]);
|
|
316
|
-
const updateEmpty = () => {
|
|
317
|
-
const el = editorRef.current;
|
|
318
|
-
if (!el) return;
|
|
319
|
-
const text = el.textContent || "";
|
|
320
|
-
const childCount = el.children.length;
|
|
321
|
-
setIsEmpty(text.length === 0 && childCount <= 1);
|
|
322
|
-
};
|
|
323
|
-
const saveSelection = () => {
|
|
324
|
-
const sel = window.getSelection();
|
|
325
|
-
if (sel && sel.rangeCount > 0 && editorRef.current?.contains(sel.anchorNode)) {
|
|
326
|
-
lastRangeRef.current = sel.getRangeAt(0).cloneRange();
|
|
327
|
-
}
|
|
328
|
-
};
|
|
329
|
-
const restoreSelection = () => {
|
|
330
|
-
const range = lastRangeRef.current;
|
|
331
|
-
if (!range) return;
|
|
332
|
-
if (!editorRef.current?.contains(range.startContainer)) {
|
|
333
|
-
lastRangeRef.current = null;
|
|
334
|
-
return;
|
|
335
|
-
}
|
|
336
|
-
const sel = window.getSelection();
|
|
337
|
-
try {
|
|
338
|
-
sel?.removeAllRanges();
|
|
339
|
-
sel?.addRange(range);
|
|
340
|
-
} catch {
|
|
341
|
-
lastRangeRef.current = null;
|
|
342
|
-
}
|
|
343
|
-
};
|
|
344
|
-
const updateActiveFormats = () => {
|
|
345
|
-
if (!editorRef.current) return;
|
|
346
|
-
const sel = window.getSelection();
|
|
347
|
-
if (!sel || !editorRef.current.contains(sel.anchorNode)) return;
|
|
348
|
-
const next = /* @__PURE__ */ new Set();
|
|
349
|
-
try {
|
|
350
|
-
if (document.queryCommandState("bold")) next.add("bold");
|
|
351
|
-
if (document.queryCommandState("italic")) next.add("italic");
|
|
352
|
-
if (document.queryCommandState("underline")) next.add("underline");
|
|
353
|
-
if (document.queryCommandState("strikethrough")) next.add("strikethrough");
|
|
354
|
-
if (document.queryCommandState("insertUnorderedList")) next.add("list");
|
|
355
|
-
if (document.queryCommandState("insertOrderedList")) next.add("ordered-list");
|
|
356
|
-
const block = String(document.queryCommandValue("formatBlock") || "").toLowerCase();
|
|
357
|
-
if (block) next.add(`block:${block}`);
|
|
358
|
-
if (document.queryCommandState("superscript")) next.add("superscript");
|
|
359
|
-
if (document.queryCommandState("subscript")) next.add("subscript");
|
|
360
|
-
} catch {
|
|
361
|
-
}
|
|
362
|
-
try {
|
|
363
|
-
const blockEl = currentBlock();
|
|
364
|
-
if (blockEl?.classList.contains("align-center")) next.add("align:center");
|
|
365
|
-
else if (blockEl?.classList.contains("align-right")) next.add("align:right");
|
|
366
|
-
else if (blockEl) next.add("align:left");
|
|
367
|
-
if (blockEl?.closest("mark")) next.add("highlight");
|
|
368
|
-
if (blockEl?.closest("ul.checklist")) next.add("checklist");
|
|
369
|
-
} catch {
|
|
370
|
-
}
|
|
371
|
-
setActiveFormats(next);
|
|
372
|
-
};
|
|
373
|
-
const exec = (cmd, val) => {
|
|
374
|
-
document.execCommand(cmd, false, val);
|
|
375
|
-
editorRef.current?.focus();
|
|
376
|
-
updateActiveFormats();
|
|
377
|
-
handleInput();
|
|
378
|
-
};
|
|
379
|
-
const setBlock = (tag) => {
|
|
380
|
-
exec("formatBlock", tag);
|
|
381
|
-
};
|
|
382
|
-
const toggleBlock = (tag) => {
|
|
383
|
-
const current = String(document.queryCommandValue("formatBlock") || "").toLowerCase();
|
|
384
|
-
setBlock(current === tag ? "p" : tag);
|
|
385
|
-
};
|
|
386
|
-
const historyRef = React.useRef([]);
|
|
387
|
-
const historyIdxRef = React.useRef(-1);
|
|
388
|
-
const lastPushAtRef = React.useRef(0);
|
|
389
|
-
const isRestoringRef = React.useRef(false);
|
|
390
|
-
const caretOffset = (rootEl) => {
|
|
391
|
-
const el = rootEl ?? editorRef.current;
|
|
392
|
-
const sel = window.getSelection();
|
|
393
|
-
if (!el || !sel || sel.rangeCount === 0 || !el.contains(sel.anchorNode)) return 0;
|
|
394
|
-
const range = sel.getRangeAt(0).cloneRange();
|
|
395
|
-
range.selectNodeContents(el);
|
|
396
|
-
range.setEnd(sel.getRangeAt(0).endContainer, sel.getRangeAt(0).endOffset);
|
|
397
|
-
return range.toString().length;
|
|
398
|
-
};
|
|
399
|
-
const setCaretOffset = (offset, rootEl) => {
|
|
400
|
-
const el = rootEl ?? editorRef.current;
|
|
401
|
-
if (!el) return;
|
|
402
|
-
const walker = document.createTreeWalker(el, NodeFilter.SHOW_TEXT);
|
|
403
|
-
let remaining = offset;
|
|
404
|
-
let node = null;
|
|
405
|
-
while (node = walker.nextNode()) {
|
|
406
|
-
const len = node.textContent?.length ?? 0;
|
|
407
|
-
if (remaining <= len) {
|
|
408
|
-
const range = document.createRange();
|
|
409
|
-
range.setStart(node, remaining);
|
|
410
|
-
range.collapse(true);
|
|
411
|
-
const sel = window.getSelection();
|
|
412
|
-
sel?.removeAllRanges();
|
|
413
|
-
sel?.addRange(range);
|
|
414
|
-
return;
|
|
415
|
-
}
|
|
416
|
-
remaining -= len;
|
|
417
|
-
}
|
|
418
|
-
placeCaretAtEnd(el);
|
|
419
|
-
};
|
|
420
|
-
const pushHistory = (force = false) => {
|
|
421
|
-
const el = editorRef.current;
|
|
422
|
-
if (!el || isRestoringRef.current) return;
|
|
423
|
-
const html = el.innerHTML;
|
|
424
|
-
const hist = historyRef.current;
|
|
425
|
-
const cur = hist[historyIdxRef.current];
|
|
426
|
-
if (cur && cur.html === html) return;
|
|
427
|
-
const now = Date.now();
|
|
428
|
-
const coalesce = !force && cur && now - lastPushAtRef.current < 500;
|
|
429
|
-
lastPushAtRef.current = now;
|
|
430
|
-
if (coalesce) {
|
|
431
|
-
hist[historyIdxRef.current] = { html, caret: caretOffset() };
|
|
432
|
-
return;
|
|
433
|
-
}
|
|
434
|
-
hist.length = historyIdxRef.current + 1;
|
|
435
|
-
hist.push({ html, caret: caretOffset() });
|
|
436
|
-
if (hist.length > 200) hist.shift();
|
|
437
|
-
historyIdxRef.current = hist.length - 1;
|
|
438
|
-
};
|
|
439
|
-
const applySnapshot = (snap) => {
|
|
440
|
-
const el = editorRef.current;
|
|
441
|
-
if (!el) return;
|
|
442
|
-
isRestoringRef.current = true;
|
|
443
|
-
el.innerHTML = snap.html;
|
|
444
|
-
setCaretOffset(snap.caret);
|
|
445
|
-
isRestoringRef.current = false;
|
|
446
|
-
lastEmittedRef.current = el.innerHTML;
|
|
447
|
-
onChange?.(el.innerHTML);
|
|
448
|
-
updateEmpty();
|
|
449
|
-
updateActiveFormats();
|
|
450
|
-
};
|
|
451
|
-
const undo = () => {
|
|
452
|
-
pushHistory(true);
|
|
453
|
-
if (historyIdxRef.current <= 0) return;
|
|
454
|
-
historyIdxRef.current -= 1;
|
|
455
|
-
applySnapshot(historyRef.current[historyIdxRef.current]);
|
|
456
|
-
};
|
|
457
|
-
const redo = () => {
|
|
458
|
-
if (historyIdxRef.current >= historyRef.current.length - 1) return;
|
|
459
|
-
historyIdxRef.current += 1;
|
|
460
|
-
applySnapshot(historyRef.current[historyIdxRef.current]);
|
|
461
|
-
};
|
|
462
|
-
const langOf = (pre) => {
|
|
463
|
-
const cls = Array.from(pre.classList).find((c) => c.startsWith("lang-"));
|
|
464
|
-
return cls?.slice(5) ?? "plain";
|
|
465
|
-
};
|
|
466
|
-
const [codeLang, setCodeLang] = React.useState("plain");
|
|
467
|
-
const highlightRafRef = React.useRef(0);
|
|
468
|
-
const rehighlight = (pre) => {
|
|
469
|
-
if (composingRef.current) return;
|
|
470
|
-
const code = pre.querySelector("code");
|
|
471
|
-
if (!code) return;
|
|
472
|
-
const lang = langOf(pre);
|
|
473
|
-
const text = code.textContent || "";
|
|
474
|
-
const next = highlight(text, lang);
|
|
475
|
-
if (code.innerHTML === next) return;
|
|
476
|
-
const caret = caretOffset(code);
|
|
477
|
-
isRestoringRef.current = true;
|
|
478
|
-
code.innerHTML = next;
|
|
479
|
-
setCaretOffset(caret, code);
|
|
480
|
-
isRestoringRef.current = false;
|
|
481
|
-
};
|
|
482
|
-
const scheduleHighlight = () => {
|
|
483
|
-
const pre = closestPre();
|
|
484
|
-
if (!pre) return;
|
|
485
|
-
cancelAnimationFrame(highlightRafRef.current);
|
|
486
|
-
highlightRafRef.current = requestAnimationFrame(() => rehighlight(pre));
|
|
487
|
-
};
|
|
488
|
-
const changeCodeLang = (lang) => {
|
|
489
|
-
const pre = closestPre();
|
|
490
|
-
if (!pre) return;
|
|
491
|
-
pushHistory(true);
|
|
492
|
-
Array.from(pre.classList).filter((c) => c.startsWith("lang-")).forEach((c) => pre.classList.remove(c));
|
|
493
|
-
if (lang !== "plain") pre.classList.add(`lang-${lang}`);
|
|
494
|
-
setCodeLang(lang);
|
|
495
|
-
rehighlight(pre);
|
|
496
|
-
handleInput();
|
|
497
|
-
};
|
|
498
|
-
const closestPre = () => {
|
|
499
|
-
const sel = window.getSelection();
|
|
500
|
-
const node = sel?.anchorNode;
|
|
501
|
-
if (!node || !editorRef.current?.contains(node)) return null;
|
|
502
|
-
const el = node.nodeType === Node.ELEMENT_NODE ? node : node.parentElement;
|
|
503
|
-
return el?.closest("pre") ?? null;
|
|
504
|
-
};
|
|
505
|
-
const insertCodeBlock = () => {
|
|
506
|
-
pushHistory(true);
|
|
507
|
-
const el = editorRef.current;
|
|
508
|
-
const sel = window.getSelection();
|
|
509
|
-
if (!el || !sel || sel.rangeCount === 0) return;
|
|
510
|
-
const existing = closestPre();
|
|
511
|
-
if (existing) {
|
|
512
|
-
const p = document.createElement("p");
|
|
513
|
-
p.textContent = existing.textContent || "";
|
|
514
|
-
if (!p.textContent) p.innerHTML = "<br>";
|
|
515
|
-
existing.replaceWith(p);
|
|
516
|
-
placeCaretAtEnd(p);
|
|
517
|
-
handleInput();
|
|
518
|
-
return;
|
|
519
|
-
}
|
|
520
|
-
const range = sel.getRangeAt(0);
|
|
521
|
-
const frag = range.cloneContents();
|
|
522
|
-
const holder = document.createElement("div");
|
|
523
|
-
holder.appendChild(frag);
|
|
524
|
-
const BLOCK = /^(p|div|h[1-6]|li|blockquote|pre|tr)$/i;
|
|
525
|
-
const linesOf = (node) => {
|
|
526
|
-
const out = [];
|
|
527
|
-
let cur = "";
|
|
528
|
-
for (const child of Array.from(node.childNodes)) {
|
|
529
|
-
if (child.nodeType === Node.TEXT_NODE) {
|
|
530
|
-
cur += child.textContent || "";
|
|
531
|
-
} else if (child.nodeName === "BR") {
|
|
532
|
-
out.push(cur);
|
|
533
|
-
cur = "";
|
|
534
|
-
} else if (BLOCK.test(child.nodeName)) {
|
|
535
|
-
if (cur) {
|
|
536
|
-
out.push(cur);
|
|
537
|
-
cur = "";
|
|
538
|
-
}
|
|
539
|
-
const sub = linesOf(child);
|
|
540
|
-
out.push(...sub.length > 0 ? sub : [""]);
|
|
541
|
-
} else {
|
|
542
|
-
cur += linesOf(child).join("\n");
|
|
543
|
-
}
|
|
544
|
-
}
|
|
545
|
-
if (cur) out.push(cur);
|
|
546
|
-
return out;
|
|
547
|
-
};
|
|
548
|
-
const text = linesOf(holder).join("\n").replace(/\n+$/, "");
|
|
549
|
-
const pre = document.createElement("pre");
|
|
550
|
-
const code = document.createElement("code");
|
|
551
|
-
code.textContent = text || "";
|
|
552
|
-
pre.appendChild(code);
|
|
553
|
-
range.deleteContents();
|
|
554
|
-
range.insertNode(pre);
|
|
555
|
-
ensureParagraphAfter(pre);
|
|
556
|
-
placeCaretAtEnd(code);
|
|
557
|
-
handleInput();
|
|
558
|
-
};
|
|
559
|
-
const insertTextAtCaret = (text) => {
|
|
560
|
-
const sel = window.getSelection();
|
|
561
|
-
if (!sel || sel.rangeCount === 0) return;
|
|
562
|
-
const range = sel.getRangeAt(0);
|
|
563
|
-
range.deleteContents();
|
|
564
|
-
const node = document.createTextNode(text);
|
|
565
|
-
range.insertNode(node);
|
|
566
|
-
range.setStartAfter(node);
|
|
567
|
-
range.collapse(true);
|
|
568
|
-
sel.removeAllRanges();
|
|
569
|
-
sel.addRange(range);
|
|
570
|
-
handleInput();
|
|
571
|
-
};
|
|
572
|
-
const ensureParagraphAfter = (node) => {
|
|
573
|
-
const next = node.nextElementSibling;
|
|
574
|
-
if (next && next.tagName === "P") return;
|
|
575
|
-
const p = document.createElement("p");
|
|
576
|
-
p.innerHTML = "<br>";
|
|
577
|
-
node.after(p);
|
|
578
|
-
};
|
|
579
|
-
const placeCaretAtEnd = (node) => {
|
|
580
|
-
const sel = window.getSelection();
|
|
581
|
-
if (!sel) return;
|
|
582
|
-
const r2 = document.createRange();
|
|
583
|
-
r2.selectNodeContents(node);
|
|
584
|
-
r2.collapse(false);
|
|
585
|
-
sel.removeAllRanges();
|
|
586
|
-
sel.addRange(r2);
|
|
587
|
-
editorRef.current?.focus();
|
|
588
|
-
};
|
|
589
|
-
const clearFormat = () => {
|
|
590
|
-
exec("removeFormat");
|
|
591
|
-
exec("unlink");
|
|
592
|
-
setBlock("p");
|
|
593
|
-
};
|
|
594
|
-
const indentList = (outdent) => {
|
|
595
|
-
exec(outdent ? "outdent" : "indent");
|
|
596
|
-
};
|
|
597
|
-
const inListItem = () => {
|
|
598
|
-
const sel = window.getSelection();
|
|
599
|
-
const node = sel?.anchorNode;
|
|
600
|
-
if (!node || !editorRef.current?.contains(node)) return false;
|
|
601
|
-
const el = node.nodeType === Node.ELEMENT_NODE ? node : node.parentElement;
|
|
602
|
-
return !!el?.closest("li");
|
|
603
|
-
};
|
|
604
|
-
const currentBlock = () => {
|
|
605
|
-
const sel = window.getSelection();
|
|
606
|
-
const node = sel?.anchorNode;
|
|
607
|
-
const root = editorRef.current;
|
|
608
|
-
if (!node || !root?.contains(node)) return null;
|
|
609
|
-
let el = node.nodeType === Node.ELEMENT_NODE ? node : node.parentElement;
|
|
610
|
-
while (el && el !== root && !/^(P|H[1-6]|LI|BLOCKQUOTE|PRE|DIV|TD|TH)$/.test(el.tagName)) {
|
|
611
|
-
el = el.parentElement;
|
|
612
|
-
}
|
|
613
|
-
return el && el !== root ? el : null;
|
|
614
|
-
};
|
|
615
|
-
const setAlign = (align) => {
|
|
616
|
-
const block = currentBlock();
|
|
617
|
-
if (!block) return;
|
|
618
|
-
pushHistory(true);
|
|
619
|
-
block.classList.remove("align-left", "align-center", "align-right");
|
|
620
|
-
if (align !== "left") block.classList.add(`align-${align}`);
|
|
621
|
-
handleInput();
|
|
622
|
-
};
|
|
623
|
-
const toggleChecklist = () => {
|
|
624
|
-
pushHistory(true);
|
|
625
|
-
const block = currentBlock();
|
|
626
|
-
const list = block?.closest("ul");
|
|
627
|
-
if (list?.classList.contains("checklist")) {
|
|
628
|
-
list.classList.remove("checklist");
|
|
629
|
-
list.querySelectorAll("li").forEach((li) => li.removeAttribute("data-checked"));
|
|
630
|
-
handleInput();
|
|
631
|
-
return;
|
|
632
|
-
}
|
|
633
|
-
if (list) {
|
|
634
|
-
list.classList.add("checklist");
|
|
635
|
-
list.querySelectorAll("li").forEach((li) => li.setAttribute("data-checked", "false"));
|
|
636
|
-
handleInput();
|
|
637
|
-
return;
|
|
638
|
-
}
|
|
639
|
-
exec("insertUnorderedList");
|
|
640
|
-
const made = currentBlock()?.closest("ul");
|
|
641
|
-
if (made) {
|
|
642
|
-
made.classList.add("checklist");
|
|
643
|
-
made.querySelectorAll("li").forEach((li) => li.setAttribute("data-checked", "false"));
|
|
644
|
-
}
|
|
645
|
-
handleInput();
|
|
646
|
-
};
|
|
647
|
-
const handleEditorClick = (e) => {
|
|
648
|
-
if (readOnly) return;
|
|
649
|
-
const target = e.target;
|
|
650
|
-
const li = target.closest?.("li");
|
|
651
|
-
if (!li || !li.closest("ul.checklist")) return;
|
|
652
|
-
const rect = li.getBoundingClientRect();
|
|
653
|
-
if (e.clientX - rect.left > 20) return;
|
|
654
|
-
e.preventDefault();
|
|
655
|
-
pushHistory(true);
|
|
656
|
-
li.setAttribute("data-checked", li.getAttribute("data-checked") === "true" ? "false" : "true");
|
|
657
|
-
handleInput();
|
|
658
|
-
};
|
|
659
|
-
const toggleHighlight = () => {
|
|
660
|
-
const sel = window.getSelection();
|
|
661
|
-
if (!sel || sel.rangeCount === 0 || sel.isCollapsed) return;
|
|
662
|
-
pushHistory(true);
|
|
663
|
-
const range = sel.getRangeAt(0);
|
|
664
|
-
const node = sel.anchorNode;
|
|
665
|
-
const el = node?.nodeType === Node.ELEMENT_NODE ? node : node?.parentElement;
|
|
666
|
-
const existing = el?.closest("mark");
|
|
667
|
-
if (existing) {
|
|
668
|
-
const parent = existing.parentNode;
|
|
669
|
-
while (existing.firstChild) parent?.insertBefore(existing.firstChild, existing);
|
|
670
|
-
parent?.removeChild(existing);
|
|
671
|
-
handleInput();
|
|
672
|
-
return;
|
|
673
|
-
}
|
|
674
|
-
const mark = document.createElement("mark");
|
|
675
|
-
try {
|
|
676
|
-
range.surroundContents(mark);
|
|
677
|
-
} catch {
|
|
678
|
-
const frag = range.extractContents();
|
|
679
|
-
mark.appendChild(frag);
|
|
680
|
-
range.insertNode(mark);
|
|
681
|
-
}
|
|
682
|
-
handleInput();
|
|
683
|
-
};
|
|
684
|
-
const insertTable = (cols = 3, rows = 2) => {
|
|
685
|
-
const sel = window.getSelection();
|
|
686
|
-
if (!sel || sel.rangeCount === 0) return;
|
|
687
|
-
pushHistory(true);
|
|
688
|
-
const table = document.createElement("table");
|
|
689
|
-
const thead = document.createElement("thead");
|
|
690
|
-
const headRow = document.createElement("tr");
|
|
691
|
-
for (let c = 0; c < cols; c++) {
|
|
692
|
-
const th = document.createElement("th");
|
|
693
|
-
th.innerHTML = "<br>";
|
|
694
|
-
headRow.appendChild(th);
|
|
695
|
-
}
|
|
696
|
-
thead.appendChild(headRow);
|
|
697
|
-
table.appendChild(thead);
|
|
698
|
-
const tbody = document.createElement("tbody");
|
|
699
|
-
for (let r2 = 0; r2 < rows; r2++) {
|
|
700
|
-
const tr = document.createElement("tr");
|
|
701
|
-
for (let c = 0; c < cols; c++) {
|
|
702
|
-
const td = document.createElement("td");
|
|
703
|
-
td.innerHTML = "<br>";
|
|
704
|
-
tr.appendChild(td);
|
|
705
|
-
}
|
|
706
|
-
tbody.appendChild(tr);
|
|
707
|
-
}
|
|
708
|
-
table.appendChild(tbody);
|
|
709
|
-
const range = sel.getRangeAt(0);
|
|
710
|
-
range.deleteContents();
|
|
711
|
-
range.insertNode(table);
|
|
712
|
-
ensureParagraphAfter(table);
|
|
713
|
-
const first = table.querySelector("th");
|
|
714
|
-
if (first) placeCaretAtEnd(first);
|
|
715
|
-
handleInput();
|
|
716
|
-
};
|
|
717
|
-
const moveTableCell = (backwards) => {
|
|
718
|
-
const block = currentBlock();
|
|
719
|
-
const cell = block?.closest("td, th");
|
|
720
|
-
if (!cell) return false;
|
|
721
|
-
const table = cell.closest("table");
|
|
722
|
-
if (!table) return false;
|
|
723
|
-
const cells = Array.from(table.querySelectorAll("td, th"));
|
|
724
|
-
const i = cells.indexOf(cell);
|
|
725
|
-
const next = cells[i + (backwards ? -1 : 1)];
|
|
726
|
-
if (next) {
|
|
727
|
-
placeCaretAtEnd(next);
|
|
728
|
-
return true;
|
|
729
|
-
}
|
|
730
|
-
if (!backwards) {
|
|
731
|
-
pushHistory(true);
|
|
732
|
-
const lastRow = table.querySelector("tbody")?.lastElementChild;
|
|
733
|
-
if (lastRow) {
|
|
734
|
-
const tr = document.createElement("tr");
|
|
735
|
-
for (let c = 0; c < lastRow.children.length; c++) {
|
|
736
|
-
const td = document.createElement("td");
|
|
737
|
-
td.innerHTML = "<br>";
|
|
738
|
-
tr.appendChild(td);
|
|
739
|
-
}
|
|
740
|
-
lastRow.after(tr);
|
|
741
|
-
placeCaretAtEnd(tr.firstElementChild);
|
|
742
|
-
handleInput();
|
|
743
|
-
return true;
|
|
744
|
-
}
|
|
745
|
-
}
|
|
746
|
-
return false;
|
|
747
|
-
};
|
|
748
|
-
const insertDivider = () => {
|
|
749
|
-
pushHistory(true);
|
|
750
|
-
exec("insertHorizontalRule");
|
|
751
|
-
const el = editorRef.current;
|
|
752
|
-
if (el && el.lastElementChild?.tagName === "HR") {
|
|
753
|
-
const p = document.createElement("p");
|
|
754
|
-
p.innerHTML = "<br>";
|
|
755
|
-
el.appendChild(p);
|
|
756
|
-
handleInput();
|
|
757
|
-
}
|
|
758
|
-
};
|
|
759
|
-
const insertImageByUrl = (url) => {
|
|
760
|
-
if (!url) return;
|
|
761
|
-
exec("insertImage", url);
|
|
762
|
-
};
|
|
763
|
-
const triggerImageUpload = async () => {
|
|
764
|
-
if (!onImageUpload) {
|
|
765
|
-
const url = window.prompt("\uC774\uBBF8\uC9C0 URL");
|
|
766
|
-
if (url) {
|
|
767
|
-
restoreSelection();
|
|
768
|
-
insertImageByUrl(url);
|
|
769
|
-
}
|
|
770
|
-
return;
|
|
771
|
-
}
|
|
772
|
-
const input = document.createElement("input");
|
|
773
|
-
input.type = "file";
|
|
774
|
-
input.accept = "image/*";
|
|
775
|
-
input.onchange = async () => {
|
|
776
|
-
const file = input.files?.[0];
|
|
777
|
-
if (!file) return;
|
|
778
|
-
try {
|
|
779
|
-
const url = await onImageUpload(file);
|
|
780
|
-
restoreSelection();
|
|
781
|
-
insertImageByUrl(url);
|
|
782
|
-
} catch (err) {
|
|
783
|
-
console.error("\uC774\uBBF8\uC9C0 \uC5C5\uB85C\uB4DC \uC2E4\uD328:", err);
|
|
784
|
-
}
|
|
785
|
-
};
|
|
786
|
-
input.click();
|
|
787
|
-
};
|
|
788
|
-
const openSlashMenu = () => {
|
|
789
|
-
if (!enableSlashCommand) return;
|
|
790
|
-
const sel = window.getSelection();
|
|
791
|
-
if (!sel || sel.rangeCount === 0) return;
|
|
792
|
-
const range = sel.getRangeAt(0);
|
|
793
|
-
slashStartRangeRef.current = range.cloneRange();
|
|
794
|
-
const rect = range.getBoundingClientRect();
|
|
795
|
-
const editorEl = editorRef.current;
|
|
796
|
-
if (!editorEl) return;
|
|
797
|
-
const editorRect = editorEl.getBoundingClientRect();
|
|
798
|
-
setSlashPos({
|
|
799
|
-
top: rect.bottom - editorRect.top + 4,
|
|
800
|
-
left: rect.left - editorRect.left
|
|
801
|
-
});
|
|
802
|
-
setSlashFilter("");
|
|
803
|
-
setSlashIdx(0);
|
|
804
|
-
setSlashOpen(true);
|
|
805
|
-
};
|
|
806
|
-
const closeSlashMenu = () => {
|
|
807
|
-
setSlashOpen(false);
|
|
808
|
-
setSlashFilter("");
|
|
809
|
-
setSlashIdx(0);
|
|
810
|
-
slashStartRangeRef.current = null;
|
|
811
|
-
};
|
|
812
|
-
const filteredSlashItems = React.useMemo(() => {
|
|
813
|
-
if (!slashFilter) return SLASH_ITEMS;
|
|
814
|
-
const f = slashFilter.toLowerCase();
|
|
815
|
-
return SLASH_ITEMS.filter((it) => it.label.toLowerCase().includes(f) || it.key.includes(f));
|
|
816
|
-
}, [slashFilter]);
|
|
817
|
-
const removeSlashTrigger = () => {
|
|
818
|
-
const sel = window.getSelection();
|
|
819
|
-
if (!sel || sel.rangeCount === 0) return;
|
|
820
|
-
const range = sel.getRangeAt(0);
|
|
821
|
-
const node = range.startContainer;
|
|
822
|
-
if (node.nodeType === Node.TEXT_NODE) {
|
|
823
|
-
const text = node.textContent || "";
|
|
824
|
-
const idx = text.lastIndexOf("/");
|
|
825
|
-
if (idx >= 0) {
|
|
826
|
-
node.textContent = text.slice(0, idx) + text.slice(range.startOffset);
|
|
827
|
-
const newRange = document.createRange();
|
|
828
|
-
newRange.setStart(node, idx);
|
|
829
|
-
newRange.collapse(true);
|
|
830
|
-
sel.removeAllRanges();
|
|
831
|
-
sel.addRange(newRange);
|
|
832
|
-
}
|
|
833
|
-
}
|
|
834
|
-
};
|
|
835
|
-
const applySlashItem = (item) => {
|
|
836
|
-
removeSlashTrigger();
|
|
837
|
-
closeSlashMenu();
|
|
838
|
-
switch (item.key) {
|
|
839
|
-
case "paragraph":
|
|
840
|
-
setBlock("p");
|
|
841
|
-
break;
|
|
842
|
-
case "heading-1":
|
|
843
|
-
toggleBlock("h1");
|
|
844
|
-
break;
|
|
845
|
-
case "heading-2":
|
|
846
|
-
toggleBlock("h2");
|
|
847
|
-
break;
|
|
848
|
-
case "heading-3":
|
|
849
|
-
toggleBlock("h3");
|
|
850
|
-
break;
|
|
851
|
-
case "list":
|
|
852
|
-
exec("insertUnorderedList");
|
|
853
|
-
break;
|
|
854
|
-
case "ordered-list":
|
|
855
|
-
exec("insertOrderedList");
|
|
856
|
-
break;
|
|
857
|
-
case "blockquote":
|
|
858
|
-
setBlock("blockquote");
|
|
859
|
-
break;
|
|
860
|
-
case "code-block":
|
|
861
|
-
insertCodeBlock();
|
|
862
|
-
break;
|
|
863
|
-
case "divider":
|
|
864
|
-
insertDivider();
|
|
865
|
-
break;
|
|
866
|
-
case "image":
|
|
867
|
-
triggerImageUpload();
|
|
868
|
-
break;
|
|
869
|
-
default:
|
|
870
|
-
break;
|
|
871
|
-
}
|
|
872
|
-
};
|
|
873
|
-
const openLinkEditor = () => {
|
|
874
|
-
saveSelection();
|
|
875
|
-
const sel = window.getSelection();
|
|
876
|
-
if (!sel || sel.rangeCount === 0) return;
|
|
877
|
-
const range = sel.getRangeAt(0);
|
|
878
|
-
const rect = range.getBoundingClientRect();
|
|
879
|
-
const editorEl2 = editorRef.current;
|
|
880
|
-
if (!editorEl2) return;
|
|
881
|
-
const editorRect = editorEl2.getBoundingClientRect();
|
|
882
|
-
setLinkPos({
|
|
883
|
-
top: rect.bottom - editorRect.top + 4,
|
|
884
|
-
left: rect.left - editorRect.left
|
|
885
|
-
});
|
|
886
|
-
const anchor = sel.anchorNode?.parentElement?.closest("a");
|
|
887
|
-
setLinkValue(anchor?.getAttribute("href") || "");
|
|
888
|
-
setLinkOpen(true);
|
|
889
|
-
};
|
|
890
|
-
const applyLink = () => {
|
|
891
|
-
restoreSelection();
|
|
892
|
-
if (linkValue) {
|
|
893
|
-
exec("createLink", linkValue);
|
|
894
|
-
const sel = window.getSelection();
|
|
895
|
-
const anchor = sel?.anchorNode?.parentElement?.closest("a");
|
|
896
|
-
if (anchor) {
|
|
897
|
-
anchor.setAttribute("target", "_blank");
|
|
898
|
-
anchor.setAttribute("rel", "noopener noreferrer");
|
|
899
|
-
}
|
|
900
|
-
} else {
|
|
901
|
-
exec("unlink");
|
|
902
|
-
}
|
|
903
|
-
setLinkOpen(false);
|
|
904
|
-
};
|
|
905
|
-
const tryMarkdownShortcut = () => {
|
|
906
|
-
if (!enableMarkdownShortcuts) return false;
|
|
907
|
-
const sel = window.getSelection();
|
|
908
|
-
if (!sel || sel.rangeCount === 0) return false;
|
|
909
|
-
const range = sel.getRangeAt(0);
|
|
910
|
-
const node = range.startContainer;
|
|
911
|
-
if (node.nodeType !== Node.TEXT_NODE) return false;
|
|
912
|
-
const text = (node.textContent || "").slice(0, range.startOffset);
|
|
913
|
-
const patterns = [
|
|
914
|
-
[/^###$/, () => setBlock("h3")],
|
|
915
|
-
[/^##$/, () => setBlock("h2")],
|
|
916
|
-
[/^#$/, () => setBlock("h1")],
|
|
917
|
-
[/^-$/, () => exec("insertUnorderedList")],
|
|
918
|
-
[/^\*$/, () => exec("insertUnorderedList")],
|
|
919
|
-
[/^1\.$/, () => exec("insertOrderedList")],
|
|
920
|
-
[/^>$/, () => setBlock("blockquote")]
|
|
921
|
-
];
|
|
922
|
-
for (const [re, fn] of patterns) {
|
|
923
|
-
if (re.test(text)) {
|
|
924
|
-
node.textContent = (node.textContent || "").slice(range.startOffset);
|
|
925
|
-
const newRange = document.createRange();
|
|
926
|
-
newRange.setStart(node, 0);
|
|
927
|
-
newRange.collapse(true);
|
|
928
|
-
sel.removeAllRanges();
|
|
929
|
-
sel.addRange(newRange);
|
|
930
|
-
fn();
|
|
931
|
-
return true;
|
|
932
|
-
}
|
|
933
|
-
}
|
|
934
|
-
return false;
|
|
935
|
-
};
|
|
936
|
-
const handleInput = () => {
|
|
937
|
-
if (composingRef.current) return;
|
|
938
|
-
const el = editorRef.current;
|
|
939
|
-
if (!el) return;
|
|
940
|
-
const html = el.innerHTML;
|
|
941
|
-
lastEmittedRef.current = html;
|
|
942
|
-
pushHistory();
|
|
943
|
-
scheduleHighlight();
|
|
944
|
-
onChange?.(html);
|
|
945
|
-
updateEmpty();
|
|
946
|
-
updateActiveFormats();
|
|
947
|
-
if (slashOpen) {
|
|
948
|
-
const sel = window.getSelection();
|
|
949
|
-
if (sel && sel.rangeCount > 0) {
|
|
950
|
-
const range = sel.getRangeAt(0);
|
|
951
|
-
const node = range.startContainer;
|
|
952
|
-
if (node.nodeType === Node.TEXT_NODE) {
|
|
953
|
-
const text = node.textContent || "";
|
|
954
|
-
const lastSlash = text.lastIndexOf("/", range.startOffset - 1);
|
|
955
|
-
if (lastSlash >= 0) {
|
|
956
|
-
const filter = text.slice(lastSlash + 1, range.startOffset);
|
|
957
|
-
if (filter.includes(" ") || filter.includes("\n")) {
|
|
958
|
-
closeSlashMenu();
|
|
959
|
-
} else {
|
|
960
|
-
setSlashFilter(filter);
|
|
961
|
-
setSlashIdx(0);
|
|
962
|
-
}
|
|
963
|
-
} else {
|
|
964
|
-
closeSlashMenu();
|
|
965
|
-
}
|
|
966
|
-
}
|
|
967
|
-
}
|
|
968
|
-
}
|
|
969
|
-
};
|
|
970
|
-
const handleKeyDown = (e) => {
|
|
971
|
-
if (readOnly) return;
|
|
972
|
-
if (composingRef.current || e.nativeEvent.isComposing || e.keyCode === 229) return;
|
|
973
|
-
const pre = closestPre();
|
|
974
|
-
if (pre && !slashOpen) {
|
|
975
|
-
if (e.key === "Enter" && !e.shiftKey) {
|
|
976
|
-
const text = pre.textContent || "";
|
|
977
|
-
if (text.endsWith("\n\n")) {
|
|
978
|
-
e.preventDefault();
|
|
979
|
-
const code = pre.querySelector("code") ?? pre;
|
|
980
|
-
code.textContent = text.replace(/\n\n$/, "");
|
|
981
|
-
ensureParagraphAfter(pre);
|
|
982
|
-
const next = pre.nextElementSibling;
|
|
983
|
-
if (next) placeCaretAtEnd(next);
|
|
984
|
-
handleInput();
|
|
985
|
-
return;
|
|
986
|
-
}
|
|
987
|
-
e.preventDefault();
|
|
988
|
-
insertTextAtCaret("\n");
|
|
989
|
-
return;
|
|
990
|
-
}
|
|
991
|
-
if (e.key === "Tab") {
|
|
992
|
-
e.preventDefault();
|
|
993
|
-
insertTextAtCaret(" ");
|
|
994
|
-
return;
|
|
995
|
-
}
|
|
996
|
-
}
|
|
997
|
-
if (e.key === "Tab" && moveTableCell(e.shiftKey)) {
|
|
998
|
-
e.preventDefault();
|
|
999
|
-
return;
|
|
1000
|
-
}
|
|
1001
|
-
if (e.key === "Tab" && inListItem()) {
|
|
1002
|
-
e.preventDefault();
|
|
1003
|
-
indentList(e.shiftKey);
|
|
1004
|
-
return;
|
|
1005
|
-
}
|
|
1006
|
-
if (slashOpen) {
|
|
1007
|
-
if (e.key === "ArrowDown") {
|
|
1008
|
-
e.preventDefault();
|
|
1009
|
-
setSlashIdx((i) => Math.min(i + 1, filteredSlashItems.length - 1));
|
|
1010
|
-
return;
|
|
1011
|
-
}
|
|
1012
|
-
if (e.key === "ArrowUp") {
|
|
1013
|
-
e.preventDefault();
|
|
1014
|
-
setSlashIdx((i) => Math.max(i - 1, 0));
|
|
1015
|
-
return;
|
|
1016
|
-
}
|
|
1017
|
-
if (e.key === "Enter") {
|
|
1018
|
-
e.preventDefault();
|
|
1019
|
-
const item = filteredSlashItems[slashIdx];
|
|
1020
|
-
if (item) applySlashItem(item);
|
|
1021
|
-
return;
|
|
1022
|
-
}
|
|
1023
|
-
if (e.key === "Escape") {
|
|
1024
|
-
e.preventDefault();
|
|
1025
|
-
closeSlashMenu();
|
|
1026
|
-
return;
|
|
1027
|
-
}
|
|
1028
|
-
}
|
|
1029
|
-
if ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === "z") {
|
|
1030
|
-
e.preventDefault();
|
|
1031
|
-
if (e.shiftKey) redo();
|
|
1032
|
-
else undo();
|
|
1033
|
-
return;
|
|
1034
|
-
}
|
|
1035
|
-
if ((e.metaKey || e.ctrlKey) && e.shiftKey && e.key.toLowerCase() === "v") {
|
|
1036
|
-
plainPasteRef.current = true;
|
|
1037
|
-
return;
|
|
1038
|
-
}
|
|
1039
|
-
if ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === "y") {
|
|
1040
|
-
e.preventDefault();
|
|
1041
|
-
redo();
|
|
1042
|
-
return;
|
|
1043
|
-
}
|
|
1044
|
-
if ((e.metaKey || e.ctrlKey) && !e.shiftKey && !e.altKey) {
|
|
1045
|
-
const k = e.key.toLowerCase();
|
|
1046
|
-
if (k === "b") {
|
|
1047
|
-
e.preventDefault();
|
|
1048
|
-
exec("bold");
|
|
1049
|
-
return;
|
|
1050
|
-
}
|
|
1051
|
-
if (k === "i") {
|
|
1052
|
-
e.preventDefault();
|
|
1053
|
-
exec("italic");
|
|
1054
|
-
return;
|
|
1055
|
-
}
|
|
1056
|
-
if (k === "u") {
|
|
1057
|
-
e.preventDefault();
|
|
1058
|
-
exec("underline");
|
|
1059
|
-
return;
|
|
1060
|
-
}
|
|
1061
|
-
if (k === "k") {
|
|
1062
|
-
e.preventDefault();
|
|
1063
|
-
openLinkEditor();
|
|
1064
|
-
return;
|
|
1065
|
-
}
|
|
1066
|
-
}
|
|
1067
|
-
if (pre) return;
|
|
1068
|
-
if (enableSlashCommand && e.key === "/") {
|
|
1069
|
-
setTimeout(openSlashMenu, 0);
|
|
1070
|
-
}
|
|
1071
|
-
if (enableMarkdownShortcuts && e.key === " ") {
|
|
1072
|
-
if (tryMarkdownShortcut()) {
|
|
1073
|
-
e.preventDefault();
|
|
1074
|
-
}
|
|
1075
|
-
}
|
|
1076
|
-
};
|
|
1077
|
-
const plainPasteRef = React.useRef(false);
|
|
1078
|
-
const handlePaste = (e) => {
|
|
1079
|
-
if (readOnly) return;
|
|
1080
|
-
e.preventDefault();
|
|
1081
|
-
const text = e.clipboardData.getData("text/plain");
|
|
1082
|
-
if (plainPasteRef.current) {
|
|
1083
|
-
plainPasteRef.current = false;
|
|
1084
|
-
insertTextAtCaret(text);
|
|
1085
|
-
return;
|
|
1086
|
-
}
|
|
1087
|
-
if (closestPre()) {
|
|
1088
|
-
insertTextAtCaret(text);
|
|
1089
|
-
return;
|
|
1090
|
-
}
|
|
1091
|
-
const html = e.clipboardData.getData("text/html");
|
|
1092
|
-
const clean = html ? sanitizeHtml(html) : escapeHtml(text);
|
|
1093
|
-
document.execCommand("insertHTML", false, clean);
|
|
1094
|
-
handleInput();
|
|
1095
|
-
};
|
|
1096
|
-
const handleCompositionStart = () => {
|
|
1097
|
-
composingRef.current = true;
|
|
1098
|
-
};
|
|
1099
|
-
const handleCompositionEnd = () => {
|
|
1100
|
-
composingRef.current = false;
|
|
1101
|
-
handleInput();
|
|
1102
|
-
};
|
|
1103
|
-
const handleFocus = () => {
|
|
1104
|
-
setIsFocused(true);
|
|
1105
|
-
updateActiveFormats();
|
|
1106
|
-
};
|
|
1107
|
-
const handleBlur = () => {
|
|
1108
|
-
setIsFocused(false);
|
|
1109
|
-
saveSelection();
|
|
1110
|
-
};
|
|
1111
|
-
const handleSelectionUpdate = () => {
|
|
1112
|
-
updateActiveFormats();
|
|
1113
|
-
const pre = closestPre();
|
|
1114
|
-
setCodeLang(pre ? langOf(pre) : "plain");
|
|
1115
|
-
};
|
|
1116
|
-
const onToolbarAction = (item) => {
|
|
1117
|
-
if (closestPre() && !["code-block", "undo", "redo"].includes(item)) return;
|
|
1118
|
-
switch (item) {
|
|
1119
|
-
case "bold":
|
|
1120
|
-
exec("bold");
|
|
1121
|
-
break;
|
|
1122
|
-
case "italic":
|
|
1123
|
-
exec("italic");
|
|
1124
|
-
break;
|
|
1125
|
-
case "underline":
|
|
1126
|
-
exec("underline");
|
|
1127
|
-
break;
|
|
1128
|
-
case "strikethrough":
|
|
1129
|
-
exec("strikethrough");
|
|
1130
|
-
break;
|
|
1131
|
-
case "code": {
|
|
1132
|
-
const sel = window.getSelection();
|
|
1133
|
-
if (!sel || sel.rangeCount === 0 || sel.isCollapsed) return;
|
|
1134
|
-
const range = sel.getRangeAt(0);
|
|
1135
|
-
const code = document.createElement("code");
|
|
1136
|
-
try {
|
|
1137
|
-
range.surroundContents(code);
|
|
1138
|
-
} catch {
|
|
1139
|
-
const frag = range.extractContents();
|
|
1140
|
-
code.appendChild(frag);
|
|
1141
|
-
range.insertNode(code);
|
|
1142
|
-
}
|
|
1143
|
-
handleInput();
|
|
1144
|
-
break;
|
|
1145
|
-
}
|
|
1146
|
-
case "heading-1":
|
|
1147
|
-
toggleBlock("h1");
|
|
1148
|
-
break;
|
|
1149
|
-
case "heading-2":
|
|
1150
|
-
toggleBlock("h2");
|
|
1151
|
-
break;
|
|
1152
|
-
case "heading-3":
|
|
1153
|
-
toggleBlock("h3");
|
|
1154
|
-
break;
|
|
1155
|
-
case "list":
|
|
1156
|
-
exec("insertUnorderedList");
|
|
1157
|
-
break;
|
|
1158
|
-
case "ordered-list":
|
|
1159
|
-
exec("insertOrderedList");
|
|
1160
|
-
break;
|
|
1161
|
-
case "blockquote":
|
|
1162
|
-
setBlock("blockquote");
|
|
1163
|
-
break;
|
|
1164
|
-
case "code-block":
|
|
1165
|
-
insertCodeBlock();
|
|
1166
|
-
break;
|
|
1167
|
-
case "link":
|
|
1168
|
-
openLinkEditor();
|
|
1169
|
-
break;
|
|
1170
|
-
case "image":
|
|
1171
|
-
triggerImageUpload();
|
|
1172
|
-
break;
|
|
1173
|
-
case "divider":
|
|
1174
|
-
insertDivider();
|
|
1175
|
-
break;
|
|
1176
|
-
case "checklist":
|
|
1177
|
-
toggleChecklist();
|
|
1178
|
-
break;
|
|
1179
|
-
case "align-left":
|
|
1180
|
-
setAlign("left");
|
|
1181
|
-
break;
|
|
1182
|
-
case "align-center":
|
|
1183
|
-
setAlign("center");
|
|
1184
|
-
break;
|
|
1185
|
-
case "align-right":
|
|
1186
|
-
setAlign("right");
|
|
1187
|
-
break;
|
|
1188
|
-
case "highlight":
|
|
1189
|
-
toggleHighlight();
|
|
1190
|
-
break;
|
|
1191
|
-
case "superscript":
|
|
1192
|
-
exec("superscript");
|
|
1193
|
-
break;
|
|
1194
|
-
case "subscript":
|
|
1195
|
-
exec("subscript");
|
|
1196
|
-
break;
|
|
1197
|
-
case "table":
|
|
1198
|
-
insertTable();
|
|
1199
|
-
break;
|
|
1200
|
-
case "clear-format":
|
|
1201
|
-
clearFormat();
|
|
1202
|
-
break;
|
|
1203
|
-
case "undo":
|
|
1204
|
-
undo();
|
|
1205
|
-
break;
|
|
1206
|
-
case "redo":
|
|
1207
|
-
redo();
|
|
1208
|
-
break;
|
|
1209
|
-
}
|
|
1210
|
-
};
|
|
1211
|
-
return /* @__PURE__ */ jsxs("div", { className: clsx_default("lib-xplat-editor", isFocused && "focused", readOnly && "readonly"), children: [
|
|
1212
|
-
!readOnly && /* @__PURE__ */ jsx(
|
|
1213
|
-
EditorToolbar,
|
|
1214
|
-
{
|
|
1215
|
-
items: toolbar,
|
|
1216
|
-
active: activeFormats,
|
|
1217
|
-
onAction: onToolbarAction,
|
|
1218
|
-
codeLang,
|
|
1219
|
-
inCodeBlock: activeFormats.has("block:pre"),
|
|
1220
|
-
onCodeLangChange: changeCodeLang
|
|
1221
|
-
}
|
|
1222
|
-
),
|
|
1223
|
-
/* @__PURE__ */ jsxs("div", { className: "lib-xplat-editor__content", style: { minHeight }, children: [
|
|
1224
|
-
isEmpty && !isFocused && /* @__PURE__ */ jsx("div", { className: "lib-xplat-editor__placeholder", children: placeholder }),
|
|
1225
|
-
/* @__PURE__ */ jsx(
|
|
1226
|
-
"div",
|
|
1227
|
-
{
|
|
1228
|
-
ref: editorRef,
|
|
1229
|
-
contentEditable: !readOnly,
|
|
1230
|
-
suppressContentEditableWarning: true,
|
|
1231
|
-
role: "textbox",
|
|
1232
|
-
"aria-multiline": "true",
|
|
1233
|
-
"aria-readonly": readOnly || void 0,
|
|
1234
|
-
"aria-label": placeholder,
|
|
1235
|
-
className: "lib-xplat-editor__editable",
|
|
1236
|
-
onInput: handleInput,
|
|
1237
|
-
onKeyDown: handleKeyDown,
|
|
1238
|
-
onClick: handleEditorClick,
|
|
1239
|
-
onKeyUp: handleSelectionUpdate,
|
|
1240
|
-
onMouseUp: handleSelectionUpdate,
|
|
1241
|
-
onPaste: handlePaste,
|
|
1242
|
-
onCompositionStart: handleCompositionStart,
|
|
1243
|
-
onCompositionEnd: handleCompositionEnd,
|
|
1244
|
-
onFocus: handleFocus,
|
|
1245
|
-
onBlur: handleBlur,
|
|
1246
|
-
spellCheck: true
|
|
1247
|
-
}
|
|
1248
|
-
),
|
|
1249
|
-
slashOpen && filteredSlashItems.length > 0 && /* @__PURE__ */ jsx(
|
|
1250
|
-
SlashMenu,
|
|
1251
|
-
{
|
|
1252
|
-
position: slashPos,
|
|
1253
|
-
items: filteredSlashItems,
|
|
1254
|
-
activeIndex: slashIdx,
|
|
1255
|
-
onSelect: applySlashItem,
|
|
1256
|
-
onClose: closeSlashMenu
|
|
1257
|
-
}
|
|
1258
|
-
),
|
|
1259
|
-
linkOpen && /* @__PURE__ */ jsx(
|
|
1260
|
-
LinkPopover,
|
|
1261
|
-
{
|
|
1262
|
-
position: linkPos,
|
|
1263
|
-
value: linkValue,
|
|
1264
|
-
onChange: setLinkValue,
|
|
1265
|
-
onConfirm: applyLink,
|
|
1266
|
-
onClose: () => setLinkOpen(false)
|
|
1267
|
-
}
|
|
1268
|
-
)
|
|
1269
|
-
] })
|
|
1270
|
-
] });
|
|
1271
|
-
};
|
|
1272
|
-
Editor.displayName = "Editor";
|
|
1273
|
-
var Editor_default = Editor;
|
|
1274
|
-
var TOOLBAR_LABEL = {
|
|
1275
|
-
bold: "B",
|
|
1276
|
-
italic: "I",
|
|
1277
|
-
underline: "U",
|
|
1278
|
-
strikethrough: "S",
|
|
1279
|
-
code: "<>",
|
|
1280
|
-
"heading-1": "H1",
|
|
1281
|
-
"heading-2": "H2",
|
|
1282
|
-
"heading-3": "H3",
|
|
1283
|
-
list: "\u2022",
|
|
1284
|
-
"ordered-list": "1.",
|
|
1285
|
-
blockquote: "\u275D",
|
|
1286
|
-
"code-block": "[ ]",
|
|
1287
|
-
link: "\u{1F517}",
|
|
1288
|
-
image: "\u{1F5BC}",
|
|
1289
|
-
divider: "\u2014",
|
|
1290
|
-
checklist: "\u2611",
|
|
1291
|
-
"align-left": "\u21E4",
|
|
1292
|
-
"align-center": "\u2194",
|
|
1293
|
-
"align-right": "\u21E5",
|
|
1294
|
-
highlight: "\u{1F58D}",
|
|
1295
|
-
superscript: "x\xB2",
|
|
1296
|
-
subscript: "x\u2082",
|
|
1297
|
-
table: "\u25A6",
|
|
1298
|
-
"clear-format": "\u232B",
|
|
1299
|
-
undo: "\u21B6",
|
|
1300
|
-
redo: "\u21B7"
|
|
1301
|
-
};
|
|
1302
|
-
var TOOLBAR_TITLE = {
|
|
1303
|
-
bold: "\uAD75\uAC8C (\u2318B)",
|
|
1304
|
-
italic: "\uAE30\uC6B8\uC784 (\u2318I)",
|
|
1305
|
-
underline: "\uBC11\uC904 (\u2318U)",
|
|
1306
|
-
strikethrough: "\uCDE8\uC18C\uC120",
|
|
1307
|
-
code: "\uC778\uB77C\uC778 \uCF54\uB4DC",
|
|
1308
|
-
"heading-1": "\uC81C\uBAA9 1",
|
|
1309
|
-
"heading-2": "\uC81C\uBAA9 2",
|
|
1310
|
-
"heading-3": "\uC81C\uBAA9 3",
|
|
1311
|
-
list: "\uAE00\uBA38\uB9AC \uAE30\uD638 \uBAA9\uB85D",
|
|
1312
|
-
"ordered-list": "\uBC88\uD638 \uB9E4\uAE30\uAE30 \uBAA9\uB85D",
|
|
1313
|
-
blockquote: "\uC778\uC6A9",
|
|
1314
|
-
"code-block": "\uCF54\uB4DC \uBE14\uB85D",
|
|
1315
|
-
link: "\uB9C1\uD06C (\u2318K)",
|
|
1316
|
-
image: "\uC774\uBBF8\uC9C0",
|
|
1317
|
-
divider: "\uAD6C\uBD84\uC120",
|
|
1318
|
-
checklist: "\uCCB4\uD06C\uB9AC\uC2A4\uD2B8",
|
|
1319
|
-
"align-left": "\uC67C\uCABD \uC815\uB82C",
|
|
1320
|
-
"align-center": "\uAC00\uC6B4\uB370 \uC815\uB82C",
|
|
1321
|
-
"align-right": "\uC624\uB978\uCABD \uC815\uB82C",
|
|
1322
|
-
highlight: "\uD615\uAD11\uD39C",
|
|
1323
|
-
superscript: "\uC704 \uCCA8\uC790",
|
|
1324
|
-
subscript: "\uC544\uB798 \uCCA8\uC790",
|
|
1325
|
-
table: "\uD45C \uC0BD\uC785",
|
|
1326
|
-
"clear-format": "\uC11C\uC2DD \uC9C0\uC6B0\uAE30",
|
|
1327
|
-
undo: "\uB418\uB3CC\uB9AC\uAE30 (\u2318Z)",
|
|
1328
|
-
redo: "\uB2E4\uC2DC\uD558\uAE30 (\u2318\u21E7Z)"
|
|
1329
|
-
};
|
|
1330
|
-
var isActive = (item, active) => {
|
|
1331
|
-
if (item === "heading-1") return active.has("block:h1");
|
|
1332
|
-
if (item === "heading-2") return active.has("block:h2");
|
|
1333
|
-
if (item === "heading-3") return active.has("block:h3");
|
|
1334
|
-
if (item === "blockquote") return active.has("block:blockquote");
|
|
1335
|
-
if (item === "code-block") return active.has("block:pre");
|
|
1336
|
-
if (item === "align-left") return active.has("align:left");
|
|
1337
|
-
if (item === "align-center") return active.has("align:center");
|
|
1338
|
-
if (item === "align-right") return active.has("align:right");
|
|
1339
|
-
return active.has(item);
|
|
1340
|
-
};
|
|
1341
|
-
var EditorToolbar = ({
|
|
1342
|
-
items,
|
|
1343
|
-
active,
|
|
1344
|
-
onAction,
|
|
1345
|
-
codeLang,
|
|
1346
|
-
inCodeBlock,
|
|
1347
|
-
onCodeLangChange
|
|
1348
|
-
}) => {
|
|
1349
|
-
return /* @__PURE__ */ jsxs("div", { className: "lib-xplat-editor__toolbar", children: [
|
|
1350
|
-
items.map((item) => /* @__PURE__ */ jsx(
|
|
1351
|
-
"button",
|
|
1352
|
-
{
|
|
1353
|
-
type: "button",
|
|
1354
|
-
className: clsx_default("lib-xplat-editor__toolbar-btn", isActive(item, active) && "active"),
|
|
1355
|
-
title: TOOLBAR_TITLE[item],
|
|
1356
|
-
onMouseDown: (e) => {
|
|
1357
|
-
e.preventDefault();
|
|
1358
|
-
onAction(item);
|
|
1359
|
-
},
|
|
1360
|
-
children: TOOLBAR_LABEL[item]
|
|
1361
|
-
},
|
|
1362
|
-
item
|
|
1363
|
-
)),
|
|
1364
|
-
inCodeBlock && /* @__PURE__ */ jsx(
|
|
1365
|
-
"select",
|
|
1366
|
-
{
|
|
1367
|
-
className: "lib-xplat-editor__lang",
|
|
1368
|
-
value: codeLang,
|
|
1369
|
-
"aria-label": "\uCF54\uB4DC \uC5B8\uC5B4",
|
|
1370
|
-
onMouseDown: (e) => e.stopPropagation(),
|
|
1371
|
-
onChange: (e) => onCodeLangChange(e.target.value),
|
|
1372
|
-
children: CODE_LANGUAGES.map((l) => /* @__PURE__ */ jsx("option", { value: l.value, children: l.label }, l.value))
|
|
1373
|
-
}
|
|
1374
|
-
)
|
|
1375
|
-
] });
|
|
1376
|
-
};
|
|
1377
|
-
var SlashMenu = ({ position, items, activeIndex, onSelect, onClose }) => {
|
|
1378
|
-
React.useEffect(() => {
|
|
1379
|
-
const handleClickOutside = (e) => {
|
|
1380
|
-
const target = e.target;
|
|
1381
|
-
const menu = document.querySelector(".lib-xplat-editor__slash-menu");
|
|
1382
|
-
if (menu && !menu.contains(target)) onClose();
|
|
1383
|
-
};
|
|
1384
|
-
window.addEventListener("mousedown", handleClickOutside);
|
|
1385
|
-
return () => window.removeEventListener("mousedown", handleClickOutside);
|
|
1386
|
-
}, [onClose]);
|
|
1387
|
-
return /* @__PURE__ */ jsx(
|
|
1388
|
-
"div",
|
|
1389
|
-
{
|
|
1390
|
-
className: "lib-xplat-editor__slash-menu",
|
|
1391
|
-
style: { top: position.top, left: position.left },
|
|
1392
|
-
children: items.map((item, i) => /* @__PURE__ */ jsxs(
|
|
1393
|
-
"button",
|
|
1394
|
-
{
|
|
1395
|
-
type: "button",
|
|
1396
|
-
className: clsx_default("lib-xplat-editor__slash-item", i === activeIndex && "active"),
|
|
1397
|
-
onMouseDown: (e) => {
|
|
1398
|
-
e.preventDefault();
|
|
1399
|
-
onSelect(item);
|
|
1400
|
-
},
|
|
1401
|
-
children: [
|
|
1402
|
-
/* @__PURE__ */ jsx("span", { className: "label", children: item.label }),
|
|
1403
|
-
item.hint && /* @__PURE__ */ jsx("span", { className: "hint", children: item.hint })
|
|
1404
|
-
]
|
|
1405
|
-
},
|
|
1406
|
-
item.key
|
|
1407
|
-
))
|
|
1408
|
-
}
|
|
1409
|
-
);
|
|
1410
|
-
};
|
|
1411
|
-
var LinkPopover = ({ position, value, onChange, onConfirm, onClose }) => {
|
|
1412
|
-
const inputRef = React.useRef(null);
|
|
1413
|
-
React.useEffect(() => {
|
|
1414
|
-
inputRef.current?.focus();
|
|
1415
|
-
}, []);
|
|
1416
|
-
return /* @__PURE__ */ jsxs(
|
|
1417
|
-
"div",
|
|
1418
|
-
{
|
|
1419
|
-
className: "lib-xplat-editor__link-popover",
|
|
1420
|
-
style: { top: position.top, left: position.left },
|
|
1421
|
-
children: [
|
|
1422
|
-
/* @__PURE__ */ jsx(
|
|
1423
|
-
"input",
|
|
1424
|
-
{
|
|
1425
|
-
ref: inputRef,
|
|
1426
|
-
type: "url",
|
|
1427
|
-
placeholder: "https://",
|
|
1428
|
-
value,
|
|
1429
|
-
onChange: (e) => onChange(e.target.value),
|
|
1430
|
-
onKeyDown: (e) => {
|
|
1431
|
-
if (e.key === "Enter") {
|
|
1432
|
-
e.preventDefault();
|
|
1433
|
-
onConfirm();
|
|
1434
|
-
}
|
|
1435
|
-
if (e.key === "Escape") {
|
|
1436
|
-
e.preventDefault();
|
|
1437
|
-
onClose();
|
|
1438
|
-
}
|
|
1439
|
-
}
|
|
1440
|
-
}
|
|
1441
|
-
),
|
|
1442
|
-
/* @__PURE__ */ jsx("button", { type: "button", onMouseDown: (e) => {
|
|
1443
|
-
e.preventDefault();
|
|
1444
|
-
onConfirm();
|
|
1445
|
-
}, children: "\uC801\uC6A9" }),
|
|
1446
|
-
/* @__PURE__ */ jsx("button", { type: "button", onMouseDown: (e) => {
|
|
1447
|
-
e.preventDefault();
|
|
1448
|
-
onClose();
|
|
1449
|
-
}, children: "\uCDE8\uC18C" })
|
|
1450
|
-
]
|
|
1451
|
-
}
|
|
1452
|
-
);
|
|
1453
|
-
};
|
|
1
|
+
import {
|
|
2
|
+
Editor_default
|
|
3
|
+
} from "../../chunk-6AIKCZN7.js";
|
|
4
|
+
import "../../chunk-7YOI5XOW.js";
|
|
5
|
+
import "../../chunk-BGXHIDUR.js";
|
|
6
|
+
import "../../chunk-KZOJN57Q.js";
|
|
1454
7
|
export {
|
|
1455
8
|
Editor_default as default
|
|
1456
9
|
};
|