unipo-ui 1.2.0 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (205) hide show
  1. package/cli/index.mjs +53 -4
  2. package/dist/EditorBlok-CarZErBW.d.cts +155 -0
  3. package/dist/EditorBlok-CarZErBW.d.ts +155 -0
  4. package/dist/admisi-LKPO7LCR.js +11 -0
  5. package/dist/admisi-U6YYQGBB.cjs +20 -0
  6. package/dist/akademik-3DFVHKUD.cjs +20 -0
  7. package/dist/akademik-IXTTJMVD.js +11 -0
  8. package/dist/akses-AUPQD6YN.cjs +20 -0
  9. package/dist/akses-V5XIMBWT.js +11 -0
  10. package/dist/arsip-23P44PGP.cjs +20 -0
  11. package/dist/arsip-NZFZOTY7.js +11 -0
  12. package/dist/cbt-4N6COVIN.js +11 -0
  13. package/dist/cbt-GMQSR7TP.cjs +20 -0
  14. package/dist/chunk-3O5ELKBH.cjs +18 -0
  15. package/dist/chunk-3O5ELKBH.cjs.map +1 -0
  16. package/dist/chunk-BCHB7R6D.cjs +614 -0
  17. package/dist/chunk-BCHB7R6D.cjs.map +1 -0
  18. package/dist/chunk-BRARGLUX.js +462 -0
  19. package/dist/chunk-BRARGLUX.js.map +1 -0
  20. package/dist/chunk-CIVK5JDV.cjs +150 -0
  21. package/dist/chunk-CIVK5JDV.cjs.map +1 -0
  22. package/dist/{chunk-SJ4DJOMZ.js → chunk-DHQFANBE.js} +178 -1557
  23. package/dist/chunk-DHQFANBE.js.map +1 -0
  24. package/dist/chunk-JSUHAYQ4.js +15 -0
  25. package/dist/chunk-JSUHAYQ4.js.map +1 -0
  26. package/dist/chunk-LTADAXBH.cjs +510 -0
  27. package/dist/chunk-LTADAXBH.cjs.map +1 -0
  28. package/dist/chunk-NCRYPHOJ.cjs +2276 -0
  29. package/dist/chunk-NCRYPHOJ.cjs.map +1 -0
  30. package/dist/chunk-PC4G2C4M.js +1007 -0
  31. package/dist/chunk-PC4G2C4M.js.map +1 -0
  32. package/dist/chunk-PYMN25WD.js +2176 -0
  33. package/dist/chunk-PYMN25WD.js.map +1 -0
  34. package/dist/chunk-PYYLKWNZ.js +537 -0
  35. package/dist/chunk-PYYLKWNZ.js.map +1 -0
  36. package/dist/chunk-QHVQ6R55.cjs +1059 -0
  37. package/dist/chunk-QHVQ6R55.cjs.map +1 -0
  38. package/dist/chunk-TITKMSUS.cjs +2186 -0
  39. package/dist/chunk-TITKMSUS.cjs.map +1 -0
  40. package/dist/chunk-UA6AUXMY.js +122 -0
  41. package/dist/chunk-UA6AUXMY.js.map +1 -0
  42. package/dist/crm-C4XGSG6O.js +11 -0
  43. package/dist/crm-LTVCDNMK.cjs +20 -0
  44. package/dist/dasbor-OJLMSFTF.cjs +20 -0
  45. package/dist/dasbor-Y3UPFYFE.js +11 -0
  46. package/dist/editor.cjs +2050 -0
  47. package/dist/editor.cjs.map +1 -0
  48. package/dist/editor.d.cts +202 -0
  49. package/dist/editor.d.ts +202 -0
  50. package/dist/editor.js +1986 -0
  51. package/dist/editor.js.map +1 -0
  52. package/dist/edom-3GZUUB7H.cjs +20 -0
  53. package/dist/edom-K4Y2NV4K.js +11 -0
  54. package/dist/fakultas-DJRUVJBV.js +11 -0
  55. package/dist/fakultas-VVAQOPUX.cjs +20 -0
  56. package/dist/filter-D54KALbB.d.cts +436 -0
  57. package/dist/filter-D54KALbB.d.ts +436 -0
  58. package/dist/helpdesk-LV65LM5V.js +11 -0
  59. package/dist/helpdesk-S7GAHYXG.cjs +20 -0
  60. package/dist/humas-7BMMJ3WF.js +11 -0
  61. package/dist/humas-H56JFUW6.cjs +20 -0
  62. package/dist/ikon.cjs +125 -0
  63. package/dist/ikon.cjs.map +1 -0
  64. package/dist/ikon.d.cts +140 -0
  65. package/dist/ikon.d.ts +140 -0
  66. package/dist/ikon.js +6 -0
  67. package/dist/ikon.js.map +1 -0
  68. package/dist/iku-CJG75NAT.cjs +20 -0
  69. package/dist/iku-XFGUJ6CX.js +11 -0
  70. package/dist/index.cjs +601 -313
  71. package/dist/index.cjs.map +1 -1
  72. package/dist/index.d.cts +192 -2
  73. package/dist/index.d.ts +192 -2
  74. package/dist/index.js +128 -4
  75. package/dist/index.js.map +1 -1
  76. package/dist/induk-BGTGKRLL.js +11 -0
  77. package/dist/induk-DLYDMZAM.cjs +20 -0
  78. package/dist/integrasi-4VXNGA3V.cjs +20 -0
  79. package/dist/integrasi-IP3WWDO7.js +11 -0
  80. package/dist/kalender-NZH7F2LO.js +11 -0
  81. package/dist/kalender-SD7EUASC.cjs +20 -0
  82. package/dist/karier-BDPZONV6.cjs +20 -0
  83. package/dist/karier-VHUJKKD6.js +11 -0
  84. package/dist/katalog.cjs +1806 -0
  85. package/dist/katalog.cjs.map +1 -0
  86. package/dist/katalog.d.cts +650 -0
  87. package/dist/katalog.d.ts +650 -0
  88. package/dist/katalog.js +1721 -0
  89. package/dist/katalog.js.map +1 -0
  90. package/dist/kelulusan-3QCPPC3D.js +11 -0
  91. package/dist/kelulusan-X7DYJN6T.cjs +20 -0
  92. package/dist/kemahasiswaan-JNCMH3HR.js +11 -0
  93. package/dist/kemahasiswaan-MQYXEVKE.cjs +20 -0
  94. package/dist/kerjasama-KYHEBSLX.cjs +20 -0
  95. package/dist/kerjasama-QSZ5X4OB.js +11 -0
  96. package/dist/keu-6H5WH6A4.js +11 -0
  97. package/dist/keu-MIJRVMGW.cjs +20 -0
  98. package/dist/kurikulum-SRO7TJYI.cjs +20 -0
  99. package/dist/kurikulum-XT7PZJOK.js +11 -0
  100. package/dist/layanan-H25JKJKC.js +11 -0
  101. package/dist/layanan-XR75P7YX.cjs +20 -0
  102. package/dist/lms-2ZCH273D.cjs +20 -0
  103. package/dist/lms-MFXFO2AZ.js +11 -0
  104. package/dist/lppm-B7ECUONV.js +11 -0
  105. package/dist/lppm-QEQKZXCY.cjs +20 -0
  106. package/dist/master-GKTTAKLF.cjs +20 -0
  107. package/dist/master-ZG4SPPDU.js +11 -0
  108. package/dist/mbkm-737Q4WFQ.js +11 -0
  109. package/dist/mbkm-GMNFIFDS.cjs +20 -0
  110. package/dist/notifikasi-FMA26M4I.js +11 -0
  111. package/dist/notifikasi-QDCYIX7G.cjs +20 -0
  112. package/dist/pddikti-RJVYY2J4.cjs +20 -0
  113. package/dist/pddikti-VF2PXDKA.js +11 -0
  114. package/dist/{content-DaJPx5LX.d.cts → pemeliharaan-D5S-1lqW.d.ts} +38 -434
  115. package/dist/{content-DaJPx5LX.d.ts → pemeliharaan-Dr0HSxvZ.d.cts} +38 -434
  116. package/dist/perpustakaan-5RL33XG2.js +11 -0
  117. package/dist/perpustakaan-JXZW43MJ.cjs +20 -0
  118. package/dist/pilih-BEes_D3n.d.cts +205 -0
  119. package/dist/pilih-CEKqXMUS.d.ts +205 -0
  120. package/dist/pmb-EGTWW2ZH.cjs +20 -0
  121. package/dist/pmb-G7EAFJ3R.js +11 -0
  122. package/dist/portal-5LCG6IP3.cjs +20 -0
  123. package/dist/portal-NYR3OIU4.js +11 -0
  124. package/dist/portal-api-BJLO6AGI.js +11 -0
  125. package/dist/portal-api-Q6B3X6ZV.cjs +20 -0
  126. package/dist/profil-FA2WXZR5.js +11 -0
  127. package/dist/profil-J4DRC6LS.cjs +20 -0
  128. package/dist/referensi-HNYOJGNX.js +11 -0
  129. package/dist/referensi-VOT5BRCL.cjs +20 -0
  130. package/dist/registry.json +996 -4
  131. package/dist/repositori-4GHBDDQA.js +11 -0
  132. package/dist/repositori-JRDIIPDJ.cjs +20 -0
  133. package/dist/rpl-4RGI6RNL.js +11 -0
  134. package/dist/rpl-NBVCZHQF.cjs +20 -0
  135. package/dist/sarpras-TAF4M2NQ.js +11 -0
  136. package/dist/sarpras-TXNUAX4Y.cjs +20 -0
  137. package/dist/scss/components/_animasi.scss +280 -0
  138. package/dist/scss/components/_editor.scss +1093 -0
  139. package/dist/scss/components/_ikon.scss +339 -0
  140. package/dist/scss/components/_katalog.scss +662 -0
  141. package/dist/scss/components/_konten-blok.scss +413 -0
  142. package/dist/scss/components/_pilih-berkas.scss +156 -0
  143. package/dist/scss/components/_platform.scss +364 -0
  144. package/dist/scss/index.scss +7 -0
  145. package/dist/sdm-5YKAAV3T.js +11 -0
  146. package/dist/sdm-IN64PE3T.cjs +20 -0
  147. package/dist/siakad.cjs +1487 -3078
  148. package/dist/siakad.cjs.map +1 -1
  149. package/dist/siakad.d.cts +84 -196
  150. package/dist/siakad.d.ts +84 -196
  151. package/dist/siakad.js +473 -2307
  152. package/dist/siakad.js.map +1 -1
  153. package/dist/spmi-AXZ5B3EJ.cjs +20 -0
  154. package/dist/spmi-LMUM2XER.js +11 -0
  155. package/dist/tracer-UBUAIJEK.js +11 -0
  156. package/dist/tracer-WWVIA55Q.cjs +20 -0
  157. package/dist/ui-unipo.css +3505 -0
  158. package/dist/ui-unipo.min.css +1 -1
  159. package/package.json +35 -3
  160. package/src/components/animasi.tsx +186 -0
  161. package/src/components/modal.tsx +113 -0
  162. package/src/components/overlays.tsx +6 -1
  163. package/src/components/pemeliharaan.tsx +152 -0
  164. package/src/components/platform.tsx +94 -0
  165. package/src/editor/EditorBerita.tsx +297 -0
  166. package/src/editor/EditorBlok.tsx +367 -0
  167. package/src/editor/Kanvas.tsx +322 -0
  168. package/src/editor/Penyisip.tsx +185 -0
  169. package/src/editor/TeksSebaris.tsx +190 -0
  170. package/src/editor/blok/Media.tsx +132 -0
  171. package/src/editor/blok/Tata.tsx +115 -0
  172. package/src/editor/blok/Teks.tsx +182 -0
  173. package/src/editor/blok/index.tsx +212 -0
  174. package/src/editor/blok/props.ts +24 -0
  175. package/src/editor/index.ts +10 -0
  176. package/src/editor/konteks.tsx +58 -0
  177. package/src/editor/render.ts +232 -0
  178. package/src/editor/tipe.ts +225 -0
  179. package/src/ikon/ilustrasi.tsx +283 -0
  180. package/src/ikon/index.ts +7 -0
  181. package/src/ikon/kotak.tsx +30 -0
  182. package/src/ikon/unipo.tsx +326 -0
  183. package/src/index.ts +8 -0
  184. package/src/katalog/aturan.ts +515 -0
  185. package/src/katalog/data/id.ts +749 -0
  186. package/src/katalog/data/indeks.json +1 -0
  187. package/src/katalog/data/muat.ts +47 -0
  188. package/src/katalog/ikon.tsx +11 -0
  189. package/src/katalog/index.ts +13 -0
  190. package/src/katalog/isian.tsx +408 -0
  191. package/src/katalog/katalog.tsx +138 -0
  192. package/src/katalog/kelola.tsx +690 -0
  193. package/src/katalog/modul.tsx +336 -0
  194. package/src/katalog/tampil.tsx +147 -0
  195. package/src/katalog/tipe.ts +141 -0
  196. package/src/katalog/wizard.tsx +155 -0
  197. package/src/lib/platform.ts +91 -0
  198. package/src/siakad/index.ts +3 -0
  199. package/src/siakad/media-editor.ts +67 -0
  200. package/src/siakad/pemeliharaan.tsx +118 -0
  201. package/src/siakad/pilih-berkas.tsx +292 -0
  202. package/src/siakad/provider.tsx +2 -0
  203. package/dist/chunk-DEF5CA7C.cjs +0 -3648
  204. package/dist/chunk-DEF5CA7C.cjs.map +0 -1
  205. package/dist/chunk-SJ4DJOMZ.js.map +0 -1
package/dist/editor.js ADDED
@@ -0,0 +1,1986 @@
1
+ 'use client';
2
+ import { Button, formatBytes, Field, Input, Dialog, SegmentedControl, Tooltip, Switch, Menu } from './chunk-PYYLKWNZ.js';
3
+ import { cn } from './chunk-JSUHAYQ4.js';
4
+ import { MoveVertical, Minus, ListCollapse, Table, Columns3, MousePointerClick, MapPin, FileDown, Film, Images, Image, Code2, Info, Quote, List, Heading2, AlignLeft, Upload, X, Search, LayoutTemplate, Plus, Trash2, Rows2, Columns2, ImagePlus, Check, Link2, Undo2, Redo2, PenLine, Eye, CheckCircle2, PanelRight, ListTree, AlertTriangle, AlignCenter, AlignRight, GripVertical, ChevronUp, ChevronDown, Copy, MoreVertical, FileText, Bold, Italic, Unlink, Highlighter, Code } from 'lucide-react';
5
+ import * as React4 from 'react';
6
+ import { useRef, useLayoutEffect, useEffect, createElement, useState } from 'react';
7
+ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
8
+ import { createPortal } from 'react-dom';
9
+
10
+ var RASIO = { "50-50": 2, "33-67": 2, "67-33": 2, "33-33-33": 3, "25-25-25-25": 4 };
11
+ var DEF = {
12
+ paragraf: { label: "Paragraf", ikon: AlignLeft, grup: "Teks", deskripsi: "Teks biasa. Ketik / untuk memilih blok.", kunci: "teks p", data: () => ({ teks: "" }), teks: true },
13
+ judul: { label: "Judul", ikon: Heading2, grup: "Teks", deskripsi: "Subjudul H2\u2013H4 untuk membagi tulisan.", kunci: "heading h2 h3 subjudul", data: () => ({ teks: "", tingkat: 2 }), teks: true },
14
+ daftar: { label: "Daftar", ikon: List, grup: "Teks", deskripsi: "Daftar berpoin atau bernomor.", kunci: "list poin nomor ul ol", data: () => ({ gaya: "ul", item: [""] }) },
15
+ kutipan: { label: "Kutipan", ikon: Quote, grup: "Teks", deskripsi: "Kutipan narasumber beserta namanya.", kunci: "quote petik", data: () => ({ teks: "", sumber: "", gaya: "biasa" }), teks: true },
16
+ sorotan: { label: "Sorotan", ikon: Info, grup: "Teks", deskripsi: "Kotak info, catatan, atau peringatan.", kunci: "callout catatan info peringatan", data: () => ({ gaya: "info", judul: "", teks: "" }) },
17
+ kode: { label: "Kode", ikon: Code2, grup: "Teks", deskripsi: "Teks monospace apa adanya.", kunci: "code pre", data: () => ({ teks: "" }) },
18
+ gambar: { label: "Gambar", ikon: Image, grup: "Media", deskripsi: "Satu foto dengan keterangan.", kunci: "foto image img", data: () => ({ url: "", alt: "", keterangan: "", lebar: "normal" }) },
19
+ galeri: { label: "Galeri", ikon: Images, grup: "Media", deskripsi: "Beberapa foto dalam kisi.", kunci: "foto album", data: () => ({ gambar: [], kolom: 3 }) },
20
+ video: { label: "Video", ikon: Film, grup: "Sematan", deskripsi: "YouTube atau Vimeo.", kunci: "youtube vimeo", data: () => ({ url: "", keterangan: "" }) },
21
+ berkas: { label: "Berkas", ikon: FileDown, grup: "Media", deskripsi: "Tautan unduh PDF/dokumen.", kunci: "file pdf unduh dokumen lampiran", data: () => ({ url: "", nama: "" }) },
22
+ peta: { label: "Peta", ikon: MapPin, grup: "Sematan", deskripsi: "Sematan Google Maps.", kunci: "map lokasi google", data: () => ({ url: "" }) },
23
+ tombol: { label: "Tombol", ikon: MousePointerClick, grup: "Tata letak", deskripsi: 'Ajakan bertindak, mis. "Daftar sekarang".', kunci: "button cta", data: () => ({ tombol: [{ label: "Selengkapnya", url: "", gaya: "utama" }], rata: "kiri" }) },
24
+ kolom: { label: "Kolom", ikon: Columns3, grup: "Tata letak", deskripsi: "Isi berdampingan 2\u20134 kolom.", kunci: "columns grid", data: () => ({ rasio: "50-50" }), anak: () => [[baru("paragraf")], [baru("paragraf")]] },
25
+ tabel: { label: "Tabel", ikon: Table, grup: "Tata letak", deskripsi: "Jadwal, biaya, atau data berbaris.", kunci: "table jadwal", data: () => ({ kepala: true, baris: [["Kolom 1", "Kolom 2"], ["", ""]], keterangan: "" }) },
26
+ akordion: { label: "Akordion", ikon: ListCollapse, grup: "Tata letak", deskripsi: "Tanya jawab yang bisa dibuka-tutup.", kunci: "faq accordion tanya jawab", data: () => ({ item: [{ judul: "", isi: "" }] }) },
27
+ pemisah: { label: "Pemisah", ikon: Minus, grup: "Tata letak", deskripsi: "Garis pemisah antarbagian.", kunci: "hr garis separator", data: () => ({ gaya: "garis" }) },
28
+ spasi: { label: "Spasi", ikon: MoveVertical, grup: "Tata letak", deskripsi: "Ruang kosong vertikal.", kunci: "spacer jarak", data: () => ({ ukuran: "sedang" }) }
29
+ };
30
+ var URUTAN_GRUP = ["Teks", "Media", "Tata letak", "Sematan"];
31
+ var urut = 0;
32
+ var idBaru = () => `b${Date.now().toString(36)}${(urut++).toString(36)}${Math.random().toString(36).slice(2, 5)}`;
33
+ function baru(tipe, data) {
34
+ const d = DEF[tipe];
35
+ const b = { id: idBaru(), tipe, data: { ...d.data(), ...data } };
36
+ if (d.anak) b.anak = d.anak();
37
+ return b;
38
+ }
39
+ function salinBaru(b) {
40
+ return { ...b, id: idBaru(), data: structuredClone(b.data), anak: b.anak?.map((k) => k.map(salinBaru)) };
41
+ }
42
+ function rapikan(daftar) {
43
+ if (!Array.isArray(daftar)) return [];
44
+ return daftar.filter((b) => !!b && typeof b === "object" && typeof b.tipe === "string" && b.tipe in DEF).map((b) => {
45
+ const tipe = b.tipe;
46
+ const out = { id: typeof b.id === "string" && b.id ? b.id : idBaru(), tipe, data: { ...DEF[tipe].data(), ...b.data ?? {} } };
47
+ if (tipe === "kolom") {
48
+ const n = RASIO[out.data.rasio] ?? 2;
49
+ const anak = Array.isArray(b.anak) ? b.anak.map((k) => rapikan(k)) : [];
50
+ out.anak = Array.from({ length: n }, (_, i) => anak[i]?.length ? anak[i] : [baru("paragraf")]);
51
+ }
52
+ return out;
53
+ });
54
+ }
55
+ var teksPolos = (html) => {
56
+ if (typeof document === "undefined") return html.replace(/<[^>]+>/g, " ");
57
+ const d = document.createElement("div");
58
+ d.innerHTML = html;
59
+ return d.textContent ?? "";
60
+ };
61
+ function teksBlok(daftar) {
62
+ const bagian = [];
63
+ for (const b of daftar) {
64
+ const d = b.data;
65
+ if (typeof d.teks === "string") bagian.push(teksPolos(d.teks));
66
+ if (typeof d.judul === "string") bagian.push(d.judul);
67
+ if (Array.isArray(d.item)) d.item.forEach((x) => bagian.push(typeof x === "string" ? teksPolos(x) : `${x.judul ?? ""} ${teksPolos(x.isi ?? "")}`));
68
+ if (Array.isArray(d.baris)) d.baris.forEach((r) => Array.isArray(r) && bagian.push(r.join(" ")));
69
+ if (typeof d.keterangan === "string") bagian.push(d.keterangan);
70
+ b.anak?.forEach((k) => bagian.push(teksBlok(k)));
71
+ }
72
+ return bagian.join(" ").replace(/\s+/g, " ").trim();
73
+ }
74
+ var hitungKata = (daftar) => {
75
+ const t = teksBlok(daftar);
76
+ return t ? t.split(" ").length : 0;
77
+ };
78
+ function cariBlok(daftar, id) {
79
+ for (const b of daftar) {
80
+ if (b.id === id) return b;
81
+ for (const k of b.anak ?? []) {
82
+ const x = cariBlok(k, id);
83
+ if (x) return x;
84
+ }
85
+ }
86
+ return null;
87
+ }
88
+ function ubahBlok(daftar, id, f) {
89
+ return daftar.map((b) => b.id === id ? f(b) : b.anak ? { ...b, anak: b.anak.map((k) => ubahBlok(k, id, f)) } : b);
90
+ }
91
+ var INLINE = /* @__PURE__ */ new Set(["STRONG", "B", "EM", "I", "A", "MARK", "CODE", "SUB", "SUP", "BR", "SPAN", "U", "S"]);
92
+ function sebaris(el) {
93
+ const salin = el.cloneNode(true);
94
+ salin.querySelectorAll("*").forEach((n) => {
95
+ if (!INLINE.has(n.tagName)) n.replaceWith(...Array.from(n.childNodes));
96
+ });
97
+ return salin.innerHTML.trim();
98
+ }
99
+ function videoDari(src) {
100
+ const yt = src.match(/youtube(?:-nocookie)?\.com\/embed\/([\w-]{6,})/);
101
+ if (yt) return `https://www.youtube.com/watch?v=${yt[1]}`;
102
+ const vm = src.match(/player\.vimeo\.com\/video\/(\d+)/);
103
+ return vm ? `https://vimeo.com/${vm[1]}` : null;
104
+ }
105
+ function htmlKeBlok(html) {
106
+ if (!html || !html.trim()) return [];
107
+ const doc = new DOMParser().parseFromString(`<div>${html}</div>`, "text/html");
108
+ const akar = doc.body.firstElementChild;
109
+ const out = [];
110
+ const paragrafLepas = [];
111
+ const tutupLepas = () => {
112
+ const t = paragrafLepas.join("").trim();
113
+ if (t) out.push(baru("paragraf", { teks: t }));
114
+ paragrafLepas.length = 0;
115
+ };
116
+ akar.childNodes.forEach((n) => {
117
+ if (n.nodeType === Node.TEXT_NODE) {
118
+ paragrafLepas.push((n.textContent ?? "").replace(/</g, "&lt;"));
119
+ return;
120
+ }
121
+ if (n.nodeType !== Node.ELEMENT_NODE) return;
122
+ const el = n;
123
+ if (INLINE.has(el.tagName)) {
124
+ paragrafLepas.push(el.outerHTML);
125
+ return;
126
+ }
127
+ tutupLepas();
128
+ const tag = el.tagName;
129
+ const img = el.querySelector("img");
130
+ const iframe = tag === "IFRAME" ? el : el.querySelector("iframe");
131
+ if (/^H[1-6]$/.test(tag)) out.push(baru("judul", { teks: sebaris(el), tingkat: Math.min(4, Math.max(2, Number(tag[1]))) }));
132
+ else if (tag === "UL" || tag === "OL") out.push(baru("daftar", { gaya: tag === "OL" ? "ol" : "ul", item: Array.from(el.children).map(sebaris) }));
133
+ else if (tag === "BLOCKQUOTE") {
134
+ const cite = el.querySelector("cite");
135
+ const sumber = cite?.textContent ?? "";
136
+ cite?.remove();
137
+ out.push(baru("kutipan", { teks: sebaris(el), sumber }));
138
+ } else if (tag === "PRE") out.push(baru("kode", { teks: el.textContent ?? "" }));
139
+ else if (tag === "HR") out.push(baru("pemisah"));
140
+ else if (tag === "TABLE") {
141
+ const baris = Array.from(el.querySelectorAll("tr")).map((tr) => Array.from(tr.children).map((td) => td.textContent?.trim() ?? ""));
142
+ out.push(baru("tabel", { baris, kepala: !!el.querySelector("th"), keterangan: el.querySelector("caption")?.textContent ?? "" }));
143
+ } else if (iframe) {
144
+ const src = iframe.getAttribute("src") ?? "";
145
+ const v = videoDari(src);
146
+ if (v) out.push(baru("video", { url: v }));
147
+ else if (/google\.[a-z.]+\/maps/.test(src)) out.push(baru("peta", { url: src }));
148
+ } else if (img && (tag === "FIGURE" || tag === "IMG" || tag === "P" && !el.textContent?.trim())) {
149
+ out.push(baru("gambar", { url: img.getAttribute("src") ?? "", alt: img.getAttribute("alt") ?? "", keterangan: el.querySelector("figcaption")?.textContent ?? "" }));
150
+ } else if (tag === "DETAILS") {
151
+ const ringkas = el.querySelector("summary");
152
+ const judul = ringkas?.textContent ?? "";
153
+ ringkas?.remove();
154
+ out.push(baru("akordion", { item: [{ judul, isi: sebaris(el) }] }));
155
+ } else {
156
+ const t = sebaris(el);
157
+ if (t) out.push(baru("paragraf", { teks: t }));
158
+ }
159
+ });
160
+ tutupLepas();
161
+ return out;
162
+ }
163
+ function cariSemua(daftar, syarat) {
164
+ const out = [];
165
+ for (const b of daftar) {
166
+ if (syarat(b)) out.push(b);
167
+ b.anak?.forEach((k) => out.push(...cariSemua(k, syarat)));
168
+ }
169
+ return out;
170
+ }
171
+ var EditorCtx = React4.createContext({
172
+ pilih: null,
173
+ setPilih: () => void 0,
174
+ fokus: null,
175
+ setFokus: () => void 0,
176
+ pilihMedia: async () => null,
177
+ pola: void 0,
178
+ baca: false
179
+ });
180
+ var useEditor = () => React4.useContext(EditorCtx);
181
+ function rapikanHtml(html) {
182
+ let h = html.replace(/<(\/?)b(\s[^>]*)?>/gi, "<$1strong>").replace(/<(\/?)i(\s[^>]*)?>/gi, "<$1em>").replace(/<\/?(span|font|div)[^>]*>/gi, "").replace(/<br\s*\/?>$/i, "");
183
+ if (/^(\s|&nbsp;|<br\s*\/?>)*$/i.test(h)) h = "";
184
+ return h;
185
+ }
186
+ var panjangTeks = (el) => (el.textContent ?? "").length;
187
+ function posisiKaret(el) {
188
+ const sel = window.getSelection();
189
+ if (!sel || sel.rangeCount === 0 || !el.contains(sel.anchorNode)) return null;
190
+ const r = sel.getRangeAt(0).cloneRange();
191
+ r.selectNodeContents(el);
192
+ r.setEnd(sel.getRangeAt(0).startContainer, sel.getRangeAt(0).startOffset);
193
+ return r.toString().length;
194
+ }
195
+ function pasangKaret(el, di) {
196
+ el.focus();
197
+ const sel = window.getSelection();
198
+ if (!sel) return;
199
+ const r = document.createRange();
200
+ if (di === "awal" || di === "akhir") {
201
+ r.selectNodeContents(el);
202
+ r.collapse(di === "awal");
203
+ } else {
204
+ let sisa = di;
205
+ const jalan = document.createTreeWalker(el, NodeFilter.SHOW_TEXT);
206
+ let n = jalan.nextNode();
207
+ let pasang = false;
208
+ while (n) {
209
+ const p = (n.textContent ?? "").length;
210
+ if (sisa <= p) {
211
+ r.setStart(n, sisa);
212
+ r.collapse(true);
213
+ pasang = true;
214
+ break;
215
+ }
216
+ sisa -= p;
217
+ n = jalan.nextNode();
218
+ }
219
+ if (!pasang) {
220
+ r.selectNodeContents(el);
221
+ r.collapse(false);
222
+ }
223
+ }
224
+ sel.removeAllRanges();
225
+ sel.addRange(r);
226
+ }
227
+ function TeksSebaris({ idFokus: idFokus2, nilai, ganti, placeholder, tag = "div", className, polos: polos3, pecah, banyakBaris, hapusAwal, panah, kunci, fokusMasuk, label }) {
228
+ const ref = useRef(null);
229
+ const { fokus, setFokus, baca } = useEditor();
230
+ const terakhir = useRef(nilai);
231
+ useLayoutEffect(() => {
232
+ const el = ref.current;
233
+ if (!el) return;
234
+ if (nilai !== terakhir.current || el.innerHTML === "" && nilai !== "") {
235
+ if (polos3) el.textContent = nilai;
236
+ else el.innerHTML = nilai;
237
+ terakhir.current = nilai;
238
+ }
239
+ }, [nilai, polos3]);
240
+ useEffect(() => {
241
+ if (idFokus2 && fokus?.id === idFokus2 && ref.current) {
242
+ pasangKaret(ref.current, fokus.di);
243
+ setFokus(null);
244
+ }
245
+ }, [fokus, idFokus2, setFokus]);
246
+ const kirim = () => {
247
+ const el = ref.current;
248
+ if (!el) return;
249
+ const h = polos3 ? el.textContent ?? "" : rapikanHtml(el.innerHTML);
250
+ terakhir.current = h;
251
+ ganti(h);
252
+ };
253
+ const onKeyDown = (e2) => {
254
+ const el = ref.current;
255
+ if (!el) return;
256
+ if (kunci?.(e2)) return;
257
+ if (e2.key === "Enter" && !e2.shiftKey && !e2.nativeEvent.isComposing) {
258
+ if (pecah) {
259
+ e2.preventDefault();
260
+ const sel = window.getSelection();
261
+ if (!sel || sel.rangeCount === 0) return;
262
+ const r = sel.getRangeAt(0);
263
+ r.deleteContents();
264
+ const ekor = document.createRange();
265
+ ekor.setStart(r.startContainer, r.startOffset);
266
+ ekor.setEnd(el, el.childNodes.length);
267
+ const tmp = document.createElement("div");
268
+ tmp.appendChild(ekor.extractContents());
269
+ const sebelum = rapikanHtml(el.innerHTML);
270
+ terakhir.current = sebelum;
271
+ pecah(sebelum, rapikanHtml(tmp.innerHTML));
272
+ return;
273
+ }
274
+ if (!banyakBaris) {
275
+ e2.preventDefault();
276
+ return;
277
+ }
278
+ }
279
+ if (e2.key === "Enter" && (e2.shiftKey || banyakBaris) && !polos3) {
280
+ e2.preventDefault();
281
+ document.execCommand("insertLineBreak");
282
+ kirim();
283
+ return;
284
+ }
285
+ if (e2.key === "Backspace" && hapusAwal) {
286
+ const sel = window.getSelection();
287
+ if (sel?.isCollapsed && posisiKaret(el) === 0) {
288
+ e2.preventDefault();
289
+ hapusAwal(polos3 ? el.textContent ?? "" : rapikanHtml(el.innerHTML));
290
+ return;
291
+ }
292
+ }
293
+ if (panah && (e2.key === "ArrowUp" || e2.key === "ArrowDown")) {
294
+ const p = posisiKaret(el);
295
+ if (e2.key === "ArrowUp" && p === 0) {
296
+ e2.preventDefault();
297
+ panah(-1);
298
+ } else if (e2.key === "ArrowDown" && p === panjangTeks(el)) {
299
+ e2.preventDefault();
300
+ panah(1);
301
+ }
302
+ }
303
+ };
304
+ return createElement(tag, {
305
+ ref,
306
+ role: "textbox",
307
+ "aria-label": label ?? placeholder,
308
+ "aria-multiline": !!(pecah || banyakBaris),
309
+ contentEditable: !baca,
310
+ suppressContentEditableWarning: true,
311
+ spellCheck: true,
312
+ "data-placeholder": placeholder,
313
+ className: cn("ub-sunting", className),
314
+ onInput: kirim,
315
+ onBlur: kirim,
316
+ onFocus: fokusMasuk,
317
+ onKeyDown,
318
+ onPaste: (e2) => {
319
+ e2.preventDefault();
320
+ const t = e2.clipboardData.getData("text/plain");
321
+ document.execCommand("insertText", false, t);
322
+ }
323
+ });
324
+ }
325
+ function Penampung({ ikon, judul, petunjuk, aksi, url, placeholderUrl = "Tempel URL lalu Enter" }) {
326
+ const [isi, setIsi] = useState("");
327
+ const [tampilUrl, setTampilUrl] = useState(!aksi);
328
+ return /* @__PURE__ */ jsxs("div", { className: "u-eb-penampung", contentEditable: false, children: [
329
+ /* @__PURE__ */ jsxs("p", { className: "u-eb-penampung-judul", children: [
330
+ ikon,
331
+ judul
332
+ ] }),
333
+ /* @__PURE__ */ jsx("p", { className: "u-eb-penampung-petunjuk", children: petunjuk }),
334
+ /* @__PURE__ */ jsxs("div", { className: "u-eb-penampung-aksi", children: [
335
+ aksi,
336
+ url && aksi && !tampilUrl && /* @__PURE__ */ jsxs(Button, { variant: "outline", size: "sm", onClick: () => setTampilUrl(true), children: [
337
+ /* @__PURE__ */ jsx(Link2, { "aria-hidden": true }),
338
+ "Dari URL"
339
+ ] })
340
+ ] }),
341
+ url && tampilUrl && /* @__PURE__ */ jsxs("form", { className: "u-eb-penampung-url", onSubmit: (e2) => {
342
+ e2.preventDefault();
343
+ if (isi.trim()) url(isi.trim());
344
+ }, children: [
345
+ /* @__PURE__ */ jsx(
346
+ "input",
347
+ {
348
+ value: isi,
349
+ onChange: (e2) => setIsi(e2.target.value),
350
+ placeholder: placeholderUrl,
351
+ autoFocus: !!aksi,
352
+ className: "u-input",
353
+ "aria-label": "URL"
354
+ }
355
+ ),
356
+ /* @__PURE__ */ jsx(Button, { size: "sm", type: "submit", children: "Pasang" })
357
+ ] })
358
+ ] });
359
+ }
360
+ function Gambar({ b, ubah }) {
361
+ const { pilihMedia } = useEditor();
362
+ const ambil = async () => {
363
+ const m = (await pilihMedia({ jenis: "gambar" }))?.[0];
364
+ if (m) ubah({ url: m.url, media_id: m.id, alt: b.data.alt || m.alt || m.judul || "" });
365
+ };
366
+ if (!b.data.url) {
367
+ return /* @__PURE__ */ jsx(
368
+ Penampung,
369
+ {
370
+ ikon: /* @__PURE__ */ jsx(Image, { "aria-hidden": true }),
371
+ judul: "Gambar",
372
+ petunjuk: "Unggah foto, pilih dari pustaka media, atau tempel URL. JPG/PNG/WebP, lebar ideal 1600 px.",
373
+ aksi: /* @__PURE__ */ jsxs(Button, { size: "sm", onClick: () => void ambil(), children: [
374
+ /* @__PURE__ */ jsx(Upload, { "aria-hidden": true }),
375
+ "Pilih gambar"
376
+ ] }),
377
+ url: (u) => ubah({ url: u })
378
+ }
379
+ );
380
+ }
381
+ const lebar = ["lebar", "penuh"].includes(b.data.lebar) ? ` ub-lebar-${b.data.lebar}` : "";
382
+ return /* @__PURE__ */ jsxs("figure", { className: `ub-gambar${lebar}`, children: [
383
+ /* @__PURE__ */ jsx("img", { src: b.data.url, alt: b.data.alt ?? "" }),
384
+ /* @__PURE__ */ jsx(TeksSebaris, { tag: "figcaption", nilai: b.data.keterangan ?? "", ganti: (h) => ubah({ keterangan: h }), placeholder: "Tambahkan keterangan foto" })
385
+ ] });
386
+ }
387
+ function Galeri({ b, ubah }) {
388
+ const { pilihMedia } = useEditor();
389
+ const gambar = Array.isArray(b.data.gambar) ? b.data.gambar : [];
390
+ const tambah = async () => {
391
+ const m = await pilihMedia({ jenis: "gambar", banyak: true });
392
+ if (m?.length) ubah({ gambar: [...gambar, ...m.map((x) => ({ url: x.url, alt: x.alt ?? x.judul ?? "", keterangan: "", media_id: x.id }))] });
393
+ };
394
+ if (gambar.length === 0) {
395
+ return /* @__PURE__ */ jsx(Penampung, { ikon: /* @__PURE__ */ jsx(Images, { "aria-hidden": true }), judul: "Galeri", petunjuk: "Pilih beberapa foto sekaligus dari pustaka media.", aksi: /* @__PURE__ */ jsxs(Button, { size: "sm", onClick: () => void tambah(), children: [
396
+ /* @__PURE__ */ jsx(Upload, { "aria-hidden": true }),
397
+ "Pilih foto"
398
+ ] }) });
399
+ }
400
+ const kolom = Math.max(2, Math.min(4, Number(b.data.kolom) || 3));
401
+ return /* @__PURE__ */ jsxs("div", { children: [
402
+ /* @__PURE__ */ jsx("div", { className: `ub-galeri ub-kolom-${kolom}`, children: gambar.map((g, i) => /* @__PURE__ */ jsxs("figure", { className: "ub-galeri-item u-eb-galeri-item", children: [
403
+ /* @__PURE__ */ jsx("img", { src: g.url, alt: g.alt ?? "" }),
404
+ /* @__PURE__ */ jsx(
405
+ "button",
406
+ {
407
+ type: "button",
408
+ "aria-label": "Buang foto",
409
+ onClick: () => ubah({ gambar: gambar.filter((_, j) => j !== i) }),
410
+ className: "u-eb-buang-foto",
411
+ children: /* @__PURE__ */ jsx(X, { "aria-hidden": true })
412
+ }
413
+ ),
414
+ /* @__PURE__ */ jsx(TeksSebaris, { tag: "figcaption", polos: true, nilai: g.keterangan ?? "", ganti: (h) => ubah({ gambar: gambar.map((x, j) => j === i ? { ...x, keterangan: h } : x) }), placeholder: "Keterangan" })
415
+ ] }, `${g.url}-${i}`)) }),
416
+ /* @__PURE__ */ jsx("button", { type: "button", onClick: () => void tambah(), className: "u-eb-tautan-aksi", children: "+ Tambah foto" })
417
+ ] });
418
+ }
419
+ function embedVideo(url) {
420
+ const u = url.trim();
421
+ const yt = u.match(/^https?:\/\/(?:www\.|m\.)?(?:youtube\.com\/(?:watch\?(?:.*&)?v=|embed\/|shorts\/|live\/)|youtu\.be\/)([A-Za-z0-9_-]{11})/);
422
+ if (yt) return `https://www.youtube-nocookie.com/embed/${yt[1]}`;
423
+ const vm = u.match(/^https?:\/\/(?:www\.|player\.)?vimeo\.com\/(?:video\/)?(\d{5,12})/);
424
+ return vm ? `https://player.vimeo.com/video/${vm[1]}` : null;
425
+ }
426
+ function Video({ b, ubah }) {
427
+ const embed = b.data.url ? embedVideo(b.data.url) : null;
428
+ if (!embed) {
429
+ return /* @__PURE__ */ jsx(
430
+ Penampung,
431
+ {
432
+ ikon: /* @__PURE__ */ jsx(Film, { "aria-hidden": true }),
433
+ judul: "Video",
434
+ petunjuk: b.data.url ? "Alamat itu bukan video YouTube/Vimeo. Coba tempel ulang." : "Tempel tautan YouTube atau Vimeo.",
435
+ url: (u) => ubah({ url: u }),
436
+ placeholderUrl: "https://www.youtube.com/watch?v=\u2026"
437
+ }
438
+ );
439
+ }
440
+ return /* @__PURE__ */ jsxs("figure", { className: "ub-video", children: [
441
+ /* @__PURE__ */ jsx("div", { className: "ub-video-bingkai", children: /* @__PURE__ */ jsx("iframe", { src: embed, title: "Video", allowFullScreen: true, loading: "lazy", className: "u-eb-tanpa-klik" }) }),
442
+ /* @__PURE__ */ jsx(TeksSebaris, { tag: "figcaption", nilai: b.data.keterangan ?? "", ganti: (h) => ubah({ keterangan: h }), placeholder: "Keterangan video" })
443
+ ] });
444
+ }
445
+ function Berkas({ b, ubah }) {
446
+ const { pilihMedia } = useEditor();
447
+ const ambil = async () => {
448
+ const m = (await pilihMedia({ jenis: "dokumen" }))?.[0];
449
+ if (m) ubah({ url: m.url, nama: b.data.nama || m.judul || m.nama || "", ukuran: m.ukuran ?? null, media_id: m.id });
450
+ };
451
+ if (!b.data.url) {
452
+ return /* @__PURE__ */ jsx(Penampung, { ikon: /* @__PURE__ */ jsx(FileDown, { "aria-hidden": true }), judul: "Berkas", petunjuk: "Lampirkan PDF/dokumen untuk diunduh pembaca.", aksi: /* @__PURE__ */ jsxs(Button, { size: "sm", onClick: () => void ambil(), children: [
453
+ /* @__PURE__ */ jsx(Upload, { "aria-hidden": true }),
454
+ "Pilih berkas"
455
+ ] }), url: (u) => ubah({ url: u }) });
456
+ }
457
+ return /* @__PURE__ */ jsxs("div", { className: "ub-berkas", children: [
458
+ /* @__PURE__ */ jsx(TeksSebaris, { tag: "span", polos: true, nilai: b.data.nama ?? "", ganti: (h) => ubah({ nama: h }), placeholder: "Nama berkas", className: "u-eb-berkas-nama" }),
459
+ b.data.ukuran ? /* @__PURE__ */ jsx("small", { className: "ub-berkas-ukuran", children: formatBytes(b.data.ukuran) }) : null
460
+ ] });
461
+ }
462
+ function urlPeta(isi) {
463
+ const src = isi.match(/src=["']([^"']+)["']/)?.[1] ?? isi.trim();
464
+ return /^https:\/\/(www\.)?google\.com\/maps\/embed\?[^"'<>\s]+$/i.test(src) ? src : null;
465
+ }
466
+ function Peta({ b, ubah }) {
467
+ const url = b.data.url ? urlPeta(b.data.url) : null;
468
+ if (!url) {
469
+ return /* @__PURE__ */ jsx(
470
+ Penampung,
471
+ {
472
+ ikon: /* @__PURE__ */ jsx(MapPin, { "aria-hidden": true }),
473
+ judul: "Peta",
474
+ petunjuk: b.data.url ? "Alamat belum benar. Di Google Maps pilih Bagikan \xBB Sematkan peta, lalu salin kodenya." : "Di Google Maps pilih Bagikan \xBB Sematkan peta, salin kode HTML-nya, lalu tempel di sini.",
475
+ url: (u) => ubah({ url: urlPeta(u) ?? u }),
476
+ placeholderUrl: '<iframe src="https://www.google.com/maps/embed?\u2026'
477
+ }
478
+ );
479
+ }
480
+ return /* @__PURE__ */ jsx("figure", { className: "ub-peta", children: /* @__PURE__ */ jsx("div", { className: "ub-video-bingkai", children: /* @__PURE__ */ jsx("iframe", { src: url, title: "Peta lokasi", loading: "lazy", className: "u-eb-tanpa-klik" }) }) });
481
+ }
482
+ var SEMUA = Object.keys(DEF);
483
+ function saringTipe(q, tipe = SEMUA) {
484
+ const k = q.trim().toLowerCase();
485
+ if (!k) return tipe;
486
+ return tipe.map((t) => {
487
+ const d = DEF[t];
488
+ const label = d.label.toLowerCase();
489
+ const skor = label.startsWith(k) ? 3 : label.includes(k) ? 2 : `${d.kunci ?? ""} ${d.deskripsi}`.toLowerCase().includes(k) ? 1 : 0;
490
+ return { t, skor };
491
+ }).filter((x) => x.skor > 0).sort((a, b) => b.skor - a.skor).map((x) => x.t);
492
+ }
493
+ var blokPola = (p) => rapikan(p.blok).map(salinBaru);
494
+ function Penyisip({ jangkar: jangkar2, pilih, tutup, tanpaKolom }) {
495
+ const { pola } = useEditor();
496
+ const [tab, setTab] = React4.useState("blok");
497
+ const [q, setQ] = React4.useState("");
498
+ const ref = React4.useRef(null);
499
+ const [pos, setPos] = React4.useState({ top: 0, left: 0 });
500
+ React4.useLayoutEffect(() => {
501
+ const r = jangkar2?.getBoundingClientRect();
502
+ if (!r) return;
503
+ const lebar = Math.min(352, window.innerWidth - 16);
504
+ const left = Math.max(8, Math.min(r.left + r.width / 2 - lebar / 2, window.innerWidth - lebar - 8));
505
+ const bawah = window.innerHeight - r.bottom;
506
+ setPos({ top: bawah > 380 ? r.bottom + 6 : Math.max(8, r.top - 386), left });
507
+ }, [jangkar2]);
508
+ React4.useEffect(() => {
509
+ const klik = (e2) => {
510
+ if (ref.current && !ref.current.contains(e2.target) && !jangkar2?.contains(e2.target)) tutup();
511
+ };
512
+ const esc = (e2) => e2.key === "Escape" && tutup();
513
+ document.addEventListener("mousedown", klik);
514
+ document.addEventListener("keydown", esc);
515
+ return () => {
516
+ document.removeEventListener("mousedown", klik);
517
+ document.removeEventListener("keydown", esc);
518
+ };
519
+ }, [jangkar2, tutup]);
520
+ const tipe = saringTipe(q, tanpaKolom ? SEMUA.filter((t) => t !== "kolom") : SEMUA);
521
+ const grupPola = React4.useMemo(() => {
522
+ const m = /* @__PURE__ */ new Map();
523
+ (pola ?? []).filter((p) => !q || `${p.nama} ${p.kategori}`.toLowerCase().includes(q.toLowerCase())).forEach((p) => m.set(p.kategori, [...m.get(p.kategori) ?? [], p]));
524
+ return [...m.entries()];
525
+ }, [pola, q]);
526
+ return createPortal(
527
+ /* @__PURE__ */ jsxs("div", { ref, style: { top: pos.top, left: pos.left }, className: "u-eb-penyisip", role: "dialog", "aria-label": "Sisipkan blok", children: [
528
+ /* @__PURE__ */ jsxs("div", { className: "u-eb-penyisip-cari", children: [
529
+ /* @__PURE__ */ jsx(Search, { "aria-hidden": true }),
530
+ /* @__PURE__ */ jsx(
531
+ "input",
532
+ {
533
+ autoFocus: true,
534
+ value: q,
535
+ onChange: (e2) => setQ(e2.target.value),
536
+ placeholder: pola ? "Cari blok atau pola" : "Cari blok",
537
+ "aria-label": "Cari blok",
538
+ onKeyDown: (e2) => {
539
+ if (e2.key === "Enter" && tab === "blok" && tipe[0]) {
540
+ e2.preventDefault();
541
+ pilih([baru(tipe[0])]);
542
+ }
543
+ }
544
+ }
545
+ )
546
+ ] }),
547
+ pola && /* @__PURE__ */ jsxs("div", { className: "u-eb-penyisip-tab", role: "tablist", children: [
548
+ /* @__PURE__ */ jsx("button", { type: "button", role: "tab", "aria-selected": tab === "blok", onClick: () => setTab("blok"), children: "Blok" }),
549
+ /* @__PURE__ */ jsxs("button", { type: "button", role: "tab", "aria-selected": tab === "pola", onClick: () => setTab("pola"), children: [
550
+ /* @__PURE__ */ jsx(LayoutTemplate, { "aria-hidden": true }),
551
+ "Pola ",
552
+ /* @__PURE__ */ jsx("span", { className: "u-eb-jumlah", children: pola.length })
553
+ ] })
554
+ ] }),
555
+ /* @__PURE__ */ jsxs("div", { className: "u-eb-penyisip-isi", children: [
556
+ tab === "blok" && (tipe.length === 0 ? /* @__PURE__ */ jsxs("p", { className: "u-eb-kosong", children: [
557
+ "Tidak ada blok \u201C",
558
+ q,
559
+ "\u201D."
560
+ ] }) : q ? /* @__PURE__ */ jsx("div", { className: "u-eb-kisi-tipe", children: tipe.map((t) => /* @__PURE__ */ jsx(TombolTipe, { t, klik: () => pilih([baru(t)]) }, t)) }) : URUTAN_GRUP.map((g) => {
561
+ const isi = tipe.filter((t) => DEF[t].grup === g);
562
+ return isi.length === 0 ? null : /* @__PURE__ */ jsxs("div", { className: "u-eb-grup", children: [
563
+ /* @__PURE__ */ jsx("p", { className: "u-eb-grup-judul", children: g }),
564
+ /* @__PURE__ */ jsx("div", { className: "u-eb-kisi-tipe", children: isi.map((t) => /* @__PURE__ */ jsx(TombolTipe, { t, klik: () => pilih([baru(t)]) }, t)) })
565
+ ] }, g);
566
+ })),
567
+ tab === "pola" && (grupPola.length === 0 ? /* @__PURE__ */ jsx("p", { className: "u-eb-kosong", children: "Belum ada pola. Simpan tulisan sebagai pola dari menu editor." }) : grupPola.map(([kat, daftar]) => /* @__PURE__ */ jsxs("div", { className: "u-eb-grup", children: [
568
+ /* @__PURE__ */ jsx("p", { className: "u-eb-grup-judul", children: kat }),
569
+ daftar.map((p) => /* @__PURE__ */ jsxs("button", { type: "button", className: "u-eb-pola", onClick: () => pilih(blokPola(p)), children: [
570
+ /* @__PURE__ */ jsx("strong", { children: p.nama }),
571
+ p.deskripsi && /* @__PURE__ */ jsx("span", { children: p.deskripsi })
572
+ ] }, p.id))
573
+ ] }, kat)))
574
+ ] })
575
+ ] }),
576
+ document.body
577
+ );
578
+ }
579
+ function TombolTipe({ t, klik }) {
580
+ const d = DEF[t];
581
+ const I = d.ikon;
582
+ return /* @__PURE__ */ jsxs("button", { type: "button", onClick: klik, title: d.deskripsi, className: "u-eb-tipe", children: [
583
+ /* @__PURE__ */ jsx(I, { "aria-hidden": true }),
584
+ d.label
585
+ ] });
586
+ }
587
+ function MenuGaris({ tipe, aktif, pilih }) {
588
+ if (tipe.length === 0) return null;
589
+ return /* @__PURE__ */ jsx("div", { className: "u-eb-menu-garis", role: "listbox", contentEditable: false, children: tipe.slice(0, 8).map((t, i) => {
590
+ const d = DEF[t];
591
+ const I = d.ikon;
592
+ return /* @__PURE__ */ jsxs(
593
+ "button",
594
+ {
595
+ type: "button",
596
+ role: "option",
597
+ "aria-selected": i === aktif,
598
+ className: cn("u-eb-menu-garis-item"),
599
+ onMouseDown: (e2) => {
600
+ e2.preventDefault();
601
+ pilih(t);
602
+ },
603
+ children: [
604
+ /* @__PURE__ */ jsx("span", { className: "u-eb-menu-garis-ikon", children: /* @__PURE__ */ jsx(I, { "aria-hidden": true }) }),
605
+ /* @__PURE__ */ jsxs("span", { children: [
606
+ /* @__PURE__ */ jsx("strong", { children: d.label }),
607
+ /* @__PURE__ */ jsx("small", { children: d.deskripsi })
608
+ ] })
609
+ ]
610
+ },
611
+ t
612
+ );
613
+ }) });
614
+ }
615
+ var polosDari = (h) => h.replace(/<[^>]+>/g, "").replace(/&nbsp;| /g, " ").replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, '"').replace(/&amp;/g, "&");
616
+ var kelasRata = (r) => r === "tengah" ? "ub-rata-tengah" : r === "kanan" ? "ub-rata-kanan" : "";
617
+ var PINTASAN = [
618
+ [/^####\s/, "judul", { tingkat: 4 }],
619
+ [/^###\s/, "judul", { tingkat: 3 }],
620
+ [/^##?\s/, "judul", { tingkat: 2 }],
621
+ [/^[-*]\s/, "daftar", { gaya: "ul" }],
622
+ [/^1[.)]\s/, "daftar", { gaya: "ol" }],
623
+ [/^>\s/, "kutipan", {}]
624
+ ];
625
+ function Paragraf({ b, ubah, ops }) {
626
+ const teks = b.data.teks ?? "";
627
+ const polos3 = polosDari(teks);
628
+ const garis = /^\/[\p{L}\d-]{0,24}$/u.test(polos3) ? polos3.slice(1) : null;
629
+ const tipe = garis !== null ? saringTipe(garis) : [];
630
+ const [aktif, setAktif] = useState(0);
631
+ useEffect(() => setAktif(0), [garis]);
632
+ const jadi = (t) => ops.ubahJadi([baru(t)]);
633
+ const ganti = (h) => {
634
+ const p = polosDari(h);
635
+ for (const [re, t, d] of PINTASAN) {
636
+ if (re.test(p)) {
637
+ const sisa = h.replace(/^(#{1,4}|[-*]|1[.)]|>|&gt;)(\s|&nbsp;)/, "");
638
+ ops.ubahJadi([baru(t, t === "daftar" ? { ...d, item: [sisa] } : { ...d, teks: sisa })]);
639
+ return;
640
+ }
641
+ }
642
+ if (p.trim() === "---") {
643
+ ops.ubahJadi([baru("pemisah"), baru("paragraf")], 1);
644
+ return;
645
+ }
646
+ ubah({ teks: h });
647
+ };
648
+ const kunci = (e2) => {
649
+ if (garis === null || tipe.length === 0) return false;
650
+ if (e2.key === "ArrowDown" || e2.key === "ArrowUp") {
651
+ e2.preventDefault();
652
+ const n = Math.min(tipe.length, 8);
653
+ setAktif((a) => (a + (e2.key === "ArrowDown" ? 1 : n - 1)) % n);
654
+ return true;
655
+ }
656
+ if (e2.key === "Enter") {
657
+ e2.preventDefault();
658
+ jadi(tipe[aktif]);
659
+ return true;
660
+ }
661
+ if (e2.key === "Escape") {
662
+ e2.preventDefault();
663
+ ubah({ teks: "" });
664
+ return true;
665
+ }
666
+ return false;
667
+ };
668
+ return /* @__PURE__ */ jsxs("div", { className: "u-eb-relatif", children: [
669
+ /* @__PURE__ */ jsx(
670
+ TeksSebaris,
671
+ {
672
+ idFokus: b.id,
673
+ tag: "p",
674
+ nilai: teks,
675
+ ganti,
676
+ placeholder: "Ketik teks, atau / untuk memilih blok",
677
+ label: "Paragraf",
678
+ className: cn("ub-paragraf", b.data.besar && "ub-pembuka", kelasRata(b.data.rata)),
679
+ pecah: ops.pecah,
680
+ hapusAwal: ops.gabungAtas,
681
+ panah: ops.panah,
682
+ kunci
683
+ }
684
+ ),
685
+ garis !== null && /* @__PURE__ */ jsx(MenuGaris, { tipe, aktif, pilih: jadi })
686
+ ] });
687
+ }
688
+ function Judul({ b, ubah, ops }) {
689
+ const t = Math.max(2, Math.min(4, Number(b.data.tingkat) || 2));
690
+ return /* @__PURE__ */ jsx(
691
+ TeksSebaris,
692
+ {
693
+ idFokus: b.id,
694
+ tag: `h${t}`,
695
+ nilai: b.data.teks ?? "",
696
+ ganti: (h) => ubah({ teks: h }),
697
+ placeholder: `Judul H${t}`,
698
+ className: cn("ub-judul", kelasRata(b.data.rata)),
699
+ pecah: (s, d) => ops.pecah(s, d),
700
+ hapusAwal: ops.gabungAtas,
701
+ panah: ops.panah
702
+ }
703
+ );
704
+ }
705
+ function Daftar({ b, ubah, ops }) {
706
+ const item = Array.isArray(b.data.item) && b.data.item.length ? b.data.item : [""];
707
+ const { setFokus } = useEditor();
708
+ const Tag = b.data.gaya === "ol" ? "ol" : "ul";
709
+ const set = (i, h) => ubah({ item: item.map((x, j) => j === i ? h : x) });
710
+ const idItem = (i) => `${b.id}~${i}`;
711
+ return /* @__PURE__ */ jsx(Tag, { className: "ub-daftar", children: item.map((x, i) => /* @__PURE__ */ jsx(
712
+ TeksSebaris,
713
+ {
714
+ idFokus: idItem(i),
715
+ tag: "li",
716
+ nilai: x,
717
+ ganti: (h) => set(i, h),
718
+ placeholder: "Butir daftar",
719
+ pecah: (sebelum, sesudah) => {
720
+ if (!sebelum && !sesudah && i === item.length - 1) {
721
+ const sisa = item.slice(0, -1);
722
+ ops.ubahJadi(sisa.length ? [{ ...b, data: { ...b.data, item: sisa } }, baru("paragraf")] : [baru("paragraf")], sisa.length ? 1 : 0);
723
+ return;
724
+ }
725
+ ubah({ item: [...item.slice(0, i), sebelum, sesudah, ...item.slice(i + 1)] });
726
+ setFokus({ id: idItem(i + 1), di: "awal" });
727
+ },
728
+ hapusAwal: (h) => {
729
+ if (i === 0) {
730
+ if (item.length === 1) ops.ubahJadi([baru("paragraf", { teks: h })]);
731
+ else ops.gabungAtas("");
732
+ return;
733
+ }
734
+ const posisi = polosDari(item[i - 1]).length;
735
+ ubah({ item: [...item.slice(0, i - 1), item[i - 1] + h, ...item.slice(i + 1)] });
736
+ setFokus({ id: idItem(i - 1), di: posisi });
737
+ },
738
+ panah: (a) => {
739
+ const j = i + a;
740
+ if (j < 0 || j >= item.length) ops.panah(a);
741
+ else setFokus({ id: idItem(j), di: a < 0 ? "akhir" : "awal" });
742
+ }
743
+ },
744
+ i
745
+ )) });
746
+ }
747
+ function Kutipan({ b, ubah, ops }) {
748
+ return /* @__PURE__ */ jsxs("blockquote", { className: cn("ub-kutipan", b.data.gaya === "sorot" && "ub-kutipan-sorot"), children: [
749
+ /* @__PURE__ */ jsx(TeksSebaris, { idFokus: b.id, tag: "p", nilai: b.data.teks ?? "", ganti: (h) => ubah({ teks: h }), placeholder: "Tulis kutipan", pecah: ops.pecah, hapusAwal: ops.gabungAtas, panah: ops.panah }),
750
+ /* @__PURE__ */ jsx(TeksSebaris, { tag: "cite", polos: true, nilai: b.data.sumber ?? "", ganti: (h) => ubah({ sumber: h }), placeholder: "Nama narasumber, jabatan", className: "ub-kutipan-sumber" })
751
+ ] });
752
+ }
753
+ function Kode({ b, ubah }) {
754
+ const ref = useRef(null);
755
+ useEffect(() => {
756
+ const el = ref.current;
757
+ if (el) {
758
+ el.style.height = "auto";
759
+ el.style.height = `${el.scrollHeight}px`;
760
+ }
761
+ }, [b.data.teks]);
762
+ return /* @__PURE__ */ jsx("pre", { className: "ub-kode", children: /* @__PURE__ */ jsx(
763
+ "textarea",
764
+ {
765
+ ref,
766
+ value: b.data.teks ?? "",
767
+ onChange: (e2) => ubah({ teks: e2.target.value }),
768
+ spellCheck: false,
769
+ placeholder: "Tulis kode atau teks apa adanya",
770
+ className: "u-eb-kode-isian",
771
+ rows: 3
772
+ }
773
+ ) });
774
+ }
775
+ var IKON_SOROTAN = { info: "Info", sukses: "Berhasil", peringatan: "Perhatian", bahaya: "Penting" };
776
+ function Sorotan({ b, ubah }) {
777
+ const gaya = ["sukses", "peringatan", "bahaya"].includes(b.data.gaya) ? b.data.gaya : "info";
778
+ return /* @__PURE__ */ jsxs("div", { className: `ub-sorotan ub-sorotan-${gaya}`, children: [
779
+ /* @__PURE__ */ jsx(TeksSebaris, { tag: "span", polos: true, nilai: b.data.judul ?? "", ganti: (h) => ubah({ judul: h }), placeholder: `Judul (mis. ${IKON_SOROTAN[gaya]})`, className: "ub-sorotan-judul" }),
780
+ /* @__PURE__ */ jsx(TeksSebaris, { idFokus: b.id, tag: "div", banyakBaris: true, nilai: b.data.teks ?? "", ganti: (h) => ubah({ teks: h }), placeholder: "Isi catatan", className: "ub-sorotan-isi" })
781
+ ] });
782
+ }
783
+ function Akordion({ b, ubah }) {
784
+ const item = Array.isArray(b.data.item) ? b.data.item : [];
785
+ const set = (i, d) => ubah({ item: item.map((x, j) => j === i ? { ...x, ...d } : x) });
786
+ return /* @__PURE__ */ jsxs("div", { className: "ub-akordion", children: [
787
+ item.map((x, i) => /* @__PURE__ */ jsxs("div", { className: "ub-akordion-item u-eb-akordion-item", "data-buka": "", children: [
788
+ /* @__PURE__ */ jsx(TeksSebaris, { tag: "div", polos: true, nilai: x.judul, ganti: (h) => set(i, { judul: h }), placeholder: "Pertanyaan atau judul", className: "ub-akordion-judul", idFokus: i === 0 ? b.id : void 0 }),
789
+ /* @__PURE__ */ jsx(TeksSebaris, { tag: "div", banyakBaris: true, nilai: x.isi, ganti: (h) => set(i, { isi: h }), placeholder: "Jawaban atau isi", className: "u-eb-akordion-isi" }),
790
+ item.length > 1 && /* @__PURE__ */ jsx("button", { type: "button", onClick: () => ubah({ item: item.filter((_, j) => j !== i) }), className: "u-eb-hapus-butir", children: "Hapus" })
791
+ ] }, i)),
792
+ /* @__PURE__ */ jsxs("button", { type: "button", onClick: () => ubah({ item: [...item, { judul: "", isi: "" }] }), className: "u-eb-tautan-aksi", children: [
793
+ /* @__PURE__ */ jsx(Plus, { "aria-hidden": true }),
794
+ "Tambah butir"
795
+ ] })
796
+ ] });
797
+ }
798
+ function TombolBlok({ b, ubah, terpilih }) {
799
+ const tombol = Array.isArray(b.data.tombol) ? b.data.tombol : [];
800
+ const set = (i, d) => ubah({ tombol: tombol.map((x, j) => j === i ? { ...x, ...d } : x) });
801
+ const rata = b.data.rata === "tengah" ? " ub-rata-tengah" : b.data.rata === "kanan" ? " ub-rata-kanan" : "";
802
+ return /* @__PURE__ */ jsxs("div", { children: [
803
+ /* @__PURE__ */ jsx("div", { className: `ub-tombol-grup${rata}`, children: tombol.map((t, i) => /* @__PURE__ */ jsx("span", { className: `ub-tombol ub-tombol-${t.gaya === "garis" ? "garis" : "utama"}`, children: /* @__PURE__ */ jsx(TeksSebaris, { tag: "span", polos: true, nilai: t.label, ganti: (h) => set(i, { label: h }), placeholder: "Label tombol" }) }, i)) }),
804
+ terpilih && /* @__PURE__ */ jsxs("div", { className: "u-eb-tombol-atur", contentEditable: false, children: [
805
+ tombol.map((t, i) => /* @__PURE__ */ jsxs("div", { className: "u-eb-tombol-baris", children: [
806
+ /* @__PURE__ */ jsx(
807
+ "input",
808
+ {
809
+ value: t.url,
810
+ onChange: (e2) => set(i, { url: e2.target.value }),
811
+ placeholder: "https://\u2026 atau /pmb",
812
+ "aria-label": `Tautan tombol ${i + 1}`,
813
+ className: "u-input",
814
+ "data-size": "sm"
815
+ }
816
+ ),
817
+ /* @__PURE__ */ jsxs("select", { value: t.gaya, onChange: (e2) => set(i, { gaya: e2.target.value }), "aria-label": "Gaya", className: "u-eb-pilih", children: [
818
+ /* @__PURE__ */ jsx("option", { value: "utama", children: "Penuh" }),
819
+ /* @__PURE__ */ jsx("option", { value: "garis", children: "Garis" })
820
+ ] }),
821
+ tombol.length > 1 && /* @__PURE__ */ jsx("button", { type: "button", onClick: () => ubah({ tombol: tombol.filter((_, j) => j !== i) }), className: "u-eb-ikon-hapus", "aria-label": "Hapus tombol", children: /* @__PURE__ */ jsx(Trash2, { "aria-hidden": true }) })
822
+ ] }, i)),
823
+ /* @__PURE__ */ jsx("button", { type: "button", onClick: () => ubah({ tombol: [...tombol, { label: "Tombol", url: "", gaya: "garis" }] }), className: "u-eb-tautan-aksi", children: "+ Tombol lain" })
824
+ ] })
825
+ ] });
826
+ }
827
+ function Pemisah({ b }) {
828
+ return /* @__PURE__ */ jsx("hr", { className: cn("ub-pemisah", b.data.gaya === "titik" && "ub-pemisah-titik") });
829
+ }
830
+ function Spasi({ b }) {
831
+ const u = ["kecil", "besar"].includes(b.data.ukuran) ? b.data.ukuran : "sedang";
832
+ return /* @__PURE__ */ jsx("div", { className: `ub-spasi ub-spasi-${u} u-eb-spasi`, "aria-label": `Spasi ${u}` });
833
+ }
834
+ function Kolom({ b, ganti }) {
835
+ const rasio = b.data.rasio in RASIO ? b.data.rasio : "50-50";
836
+ const anak = b.anak ?? [];
837
+ return /* @__PURE__ */ jsx("div", { className: `ub-kolom-grup ub-rasio-${rasio}`, children: anak.map((k, i) => /* @__PURE__ */ jsx("div", { className: "ub-kolom u-eb-kolom", children: /* @__PURE__ */ jsx(Kanvas, { daftar: k, ganti: (baruK) => ganti({ ...b, anak: anak.map((x, j) => j === i ? baruK.length ? baruK : [baru("paragraf")] : x) }), dalamKolom: true }) }, i)) });
838
+ }
839
+ function aturRasio(b, rasio) {
840
+ const n = RASIO[rasio] ?? 2;
841
+ const lama = b.anak ?? [];
842
+ let anak = lama.slice(0, n);
843
+ if (lama.length > n) anak[n - 1] = [...anak[n - 1], ...lama.slice(n).flat()];
844
+ while (anak.length < n) anak = [...anak, [baru("paragraf")]];
845
+ return { ...b, data: { ...b.data, rasio }, anak };
846
+ }
847
+ function Tabel({ b, ubah, terpilih }) {
848
+ const baris = Array.isArray(b.data.baris) && b.data.baris.length ? b.data.baris : [[""]];
849
+ const lebar = Math.max(...baris.map((r) => r.length));
850
+ const set = (i, j, v) => ubah({ baris: baris.map((r, a) => a === i ? Array.from({ length: lebar }, (_, c) => c === j ? v : r[c] ?? "") : r) });
851
+ const tambahBaris = () => ubah({ baris: [...baris, Array(lebar).fill("")] });
852
+ const tambahKolom = () => ubah({ baris: baris.map((r) => [...r, ...Array(lebar - r.length + 1).fill("")]) });
853
+ const kepala = !!b.data.kepala;
854
+ return /* @__PURE__ */ jsxs("figure", { className: "ub-tabel", children: [
855
+ /* @__PURE__ */ jsx("table", { children: /* @__PURE__ */ jsx("tbody", { children: baris.map((r, i) => /* @__PURE__ */ jsxs("tr", { className: "u-eb-tr", children: [
856
+ Array.from({ length: lebar }, (_, j) => {
857
+ const Sel = kepala && i === 0 ? "th" : "td";
858
+ return /* @__PURE__ */ jsx(Sel, { children: /* @__PURE__ */ jsx(TeksSebaris, { tag: "div", nilai: r[j] ?? "", ganti: (h) => set(i, j, h), placeholder: kepala && i === 0 ? "Judul" : "" }) }, j);
859
+ }),
860
+ terpilih && baris.length > 1 && /* @__PURE__ */ jsx("td", { className: "u-eb-td-aksi", contentEditable: false, children: /* @__PURE__ */ jsx("button", { type: "button", onClick: () => ubah({ baris: baris.filter((_, a) => a !== i) }), className: "u-eb-ikon-hapus", "aria-label": "Hapus baris", children: /* @__PURE__ */ jsx(Trash2, { "aria-hidden": true }) }) })
861
+ ] }, i)) }) }),
862
+ /* @__PURE__ */ jsx(TeksSebaris, { tag: "figcaption", nilai: b.data.keterangan ?? "", ganti: (h) => ubah({ keterangan: h }), placeholder: "Keterangan tabel (opsional)" }),
863
+ terpilih && /* @__PURE__ */ jsxs("div", { className: "u-eb-tabel-aksi", contentEditable: false, children: [
864
+ /* @__PURE__ */ jsxs("button", { type: "button", onClick: tambahBaris, className: "u-eb-tautan-aksi", children: [
865
+ /* @__PURE__ */ jsx(Rows2, { "aria-hidden": true }),
866
+ "Baris"
867
+ ] }),
868
+ /* @__PURE__ */ jsxs("button", { type: "button", onClick: tambahKolom, className: "u-eb-tautan-aksi", children: [
869
+ /* @__PURE__ */ jsx(Columns2, { "aria-hidden": true }),
870
+ "Kolom"
871
+ ] }),
872
+ lebar > 1 && /* @__PURE__ */ jsxs("button", { type: "button", onClick: () => ubah({ baris: baris.map((r) => r.slice(0, lebar - 1)) }), className: "u-eb-tautan-aksi", "data-bahaya": "", children: [
873
+ /* @__PURE__ */ jsx(Plus, { "aria-hidden": true, style: { rotate: "45deg" } }),
874
+ "Kolom terakhir"
875
+ ] })
876
+ ] })
877
+ ] });
878
+ }
879
+ var RENDER = {
880
+ paragraf: Paragraf,
881
+ judul: Judul,
882
+ daftar: Daftar,
883
+ kutipan: Kutipan,
884
+ kode: Kode,
885
+ sorotan: Sorotan,
886
+ akordion: Akordion,
887
+ gambar: Gambar,
888
+ galeri: Galeri,
889
+ video: Video,
890
+ berkas: Berkas,
891
+ peta: Peta,
892
+ tombol: TombolBlok,
893
+ pemisah: Pemisah,
894
+ spasi: Spasi,
895
+ kolom: Kolom,
896
+ tabel: Tabel
897
+ };
898
+ var BISA_UBAH = ["paragraf", "judul", "kutipan", "daftar", "sorotan"];
899
+ var teksUtama = (b) => Array.isArray(b.data.item) ? b.data.item.filter((x) => typeof x === "string").join("<br>") : String(b.data.teks ?? "");
900
+ function ubahTipe(b, ke) {
901
+ const teks = teksUtama(b);
902
+ const data = ke === "daftar" ? { ...DEF.daftar.data(), item: teks.split(/<br\s*\/?>/i) } : { ...DEF[ke].data(), teks };
903
+ return { id: b.id, tipe: ke, data };
904
+ }
905
+ function Pilihan({ label, nilai, ganti, item }) {
906
+ return /* @__PURE__ */ jsx(Field, { label, children: /* @__PURE__ */ jsx(SegmentedControl, { "aria-label": label, fullWidth: true, value: nilai, onValueChange: ganti, options: item.map((x) => ({ value: x.v, label: x.label, "aria-label": x.aria })) }) });
907
+ }
908
+ function Rata({ nilai, ganti }) {
909
+ return /* @__PURE__ */ jsx(
910
+ Pilihan,
911
+ {
912
+ label: "Perataan",
913
+ nilai: nilai === "tengah" || nilai === "kanan" ? nilai : "kiri",
914
+ ganti,
915
+ item: [
916
+ { v: "kiri", label: /* @__PURE__ */ jsx(AlignLeft, { "aria-hidden": true }), aria: "Kiri" },
917
+ { v: "tengah", label: /* @__PURE__ */ jsx(AlignCenter, { "aria-hidden": true }), aria: "Tengah" },
918
+ { v: "kanan", label: /* @__PURE__ */ jsx(AlignRight, { "aria-hidden": true }), aria: "Kanan" }
919
+ ]
920
+ }
921
+ );
922
+ }
923
+ function Saklar({ nilai, ganti, label, sub }) {
924
+ const id = React4.useId();
925
+ return /* @__PURE__ */ jsxs("div", { className: "u-eb-saklar", children: [
926
+ /* @__PURE__ */ jsxs("span", { children: [
927
+ /* @__PURE__ */ jsx("label", { htmlFor: id, children: label }),
928
+ sub && /* @__PURE__ */ jsx("small", { children: sub })
929
+ ] }),
930
+ /* @__PURE__ */ jsx(Switch, { id, checked: nilai, onCheckedChange: (v) => ganti(Boolean(v)) })
931
+ ] });
932
+ }
933
+ function PengaturanBlok({ b, ganti }) {
934
+ const { pilihMedia } = useEditor();
935
+ const d = b.data;
936
+ const ubah = (x) => ganti({ ...b, data: { ...d, ...x } });
937
+ const isi = [];
938
+ switch (b.tipe) {
939
+ case "paragraf":
940
+ isi.push(
941
+ /* @__PURE__ */ jsx(Rata, { nilai: d.rata, ganti: (v) => ubah({ rata: v }) }, "r"),
942
+ /* @__PURE__ */ jsx(Saklar, { nilai: !!d.besar, ganti: (v) => ubah({ besar: v }), label: "Paragraf pembuka", sub: "Huruf lebih besar untuk alinea pertama berita." }, "b")
943
+ );
944
+ break;
945
+ case "judul":
946
+ isi.push(
947
+ /* @__PURE__ */ jsx(Pilihan, { label: "Tingkat", nilai: String(d.tingkat ?? 2), ganti: (v) => ubah({ tingkat: Number(v) }), item: [{ v: "2", label: "H2" }, { v: "3", label: "H3" }, { v: "4", label: "H4" }] }, "t"),
948
+ /* @__PURE__ */ jsx(Rata, { nilai: d.rata, ganti: (v) => ubah({ rata: v }) }, "r")
949
+ );
950
+ break;
951
+ case "daftar":
952
+ isi.push(/* @__PURE__ */ jsx(Pilihan, { label: "Gaya", nilai: d.gaya === "ol" ? "ol" : "ul", ganti: (v) => ubah({ gaya: v }), item: [{ v: "ul", label: "Poin" }, { v: "ol", label: "Nomor" }] }, "g"));
953
+ break;
954
+ case "kutipan":
955
+ isi.push(/* @__PURE__ */ jsx(Pilihan, { label: "Gaya", nilai: d.gaya === "sorot" ? "sorot" : "biasa", ganti: (v) => ubah({ gaya: v }), item: [{ v: "biasa", label: "Biasa" }, { v: "sorot", label: "Sorot besar" }] }, "g"));
956
+ break;
957
+ case "sorotan":
958
+ isi.push(
959
+ /* @__PURE__ */ jsx(Pilihan, { label: "Warna", nilai: ["sukses", "peringatan", "bahaya"].includes(d.gaya) ? d.gaya : "info", ganti: (v) => ubah({ gaya: v }), item: [{ v: "info", label: "Info" }, { v: "sukses", label: "Hijau" }, { v: "peringatan", label: "Kuning" }, { v: "bahaya", label: "Merah" }] }, "g")
960
+ );
961
+ break;
962
+ case "gambar":
963
+ isi.push(
964
+ /* @__PURE__ */ jsx(Field, { label: "Teks alternatif", description: "Gambarkan isi foto untuk pembaca layar dan mesin pencari.", children: /* @__PURE__ */ jsx(Input, { value: d.alt ?? "", onChange: (e2) => ubah({ alt: e2.target.value }) }) }, "a"),
965
+ /* @__PURE__ */ jsx(Pilihan, { label: "Lebar", nilai: ["lebar", "penuh"].includes(d.lebar) ? d.lebar : "normal", ganti: (v) => ubah({ lebar: v }), item: [{ v: "normal", label: "Normal" }, { v: "lebar", label: "Lebar" }, { v: "penuh", label: "Penuh" }] }, "l"),
966
+ /* @__PURE__ */ jsx(Field, { label: "Tautan saat diklik", children: /* @__PURE__ */ jsx(Input, { value: d.tautan ?? "", onChange: (e2) => ubah({ tautan: e2.target.value }), placeholder: "https://\u2026" }) }, "t"),
967
+ /* @__PURE__ */ jsx(
968
+ Button,
969
+ {
970
+ variant: "outline",
971
+ size: "sm",
972
+ onClick: async () => {
973
+ const m = (await pilihMedia({ jenis: "gambar" }))?.[0];
974
+ if (m) ubah({ url: m.url, media_id: m.id });
975
+ },
976
+ children: "Ganti gambar"
977
+ },
978
+ "g"
979
+ )
980
+ );
981
+ break;
982
+ case "galeri":
983
+ isi.push(/* @__PURE__ */ jsx(Pilihan, { label: "Kolom", nilai: String(d.kolom ?? 3), ganti: (v) => ubah({ kolom: Number(v) }), item: [{ v: "2", label: "2" }, { v: "3", label: "3" }, { v: "4", label: "4" }] }, "k"));
984
+ break;
985
+ case "video":
986
+ isi.push(
987
+ /* @__PURE__ */ jsx(Field, { label: "Alamat video", children: /* @__PURE__ */ jsx(Input, { value: d.url ?? "", onChange: (e2) => ubah({ url: e2.target.value }), placeholder: "https://youtu.be/\u2026" }) }, "u")
988
+ );
989
+ break;
990
+ case "peta":
991
+ isi.push(
992
+ /* @__PURE__ */ jsx(Field, { label: "URL sematan Google Maps", children: /* @__PURE__ */ jsx(Input, { value: d.url ?? "", onChange: (e2) => ubah({ url: urlPeta(e2.target.value) ?? e2.target.value }) }) }, "u")
993
+ );
994
+ break;
995
+ case "berkas":
996
+ isi.push(
997
+ /* @__PURE__ */ jsx(Field, { label: "Nama berkas", children: /* @__PURE__ */ jsx(Input, { value: d.nama ?? "", onChange: (e2) => ubah({ nama: e2.target.value }) }) }, "n"),
998
+ /* @__PURE__ */ jsx(Field, { label: "URL", children: /* @__PURE__ */ jsx(Input, { value: d.url ?? "", onChange: (e2) => ubah({ url: e2.target.value }) }) }, "u")
999
+ );
1000
+ break;
1001
+ case "tombol":
1002
+ isi.push(/* @__PURE__ */ jsx(Rata, { nilai: d.rata, ganti: (v) => ubah({ rata: v }) }, "r"));
1003
+ break;
1004
+ case "pemisah":
1005
+ isi.push(/* @__PURE__ */ jsx(Pilihan, { label: "Gaya", nilai: d.gaya === "titik" ? "titik" : "garis", ganti: (v) => ubah({ gaya: v }), item: [{ v: "garis", label: "Garis" }, { v: "titik", label: "Titik" }] }, "g"));
1006
+ break;
1007
+ case "spasi":
1008
+ isi.push(/* @__PURE__ */ jsx(Pilihan, { label: "Tinggi", nilai: ["kecil", "besar"].includes(d.ukuran) ? d.ukuran : "sedang", ganti: (v) => ubah({ ukuran: v }), item: [{ v: "kecil", label: "Kecil" }, { v: "sedang", label: "Sedang" }, { v: "besar", label: "Besar" }] }, "u"));
1009
+ break;
1010
+ case "kolom":
1011
+ isi.push(
1012
+ /* @__PURE__ */ jsx(
1013
+ Pilihan,
1014
+ {
1015
+ label: "Susunan",
1016
+ nilai: d.rasio ?? "50-50",
1017
+ ganti: (v) => ganti(aturRasio(b, v)),
1018
+ item: [
1019
+ { v: "50-50", label: "\xBD \xBD" },
1020
+ { v: "33-67", label: "\u2153 \u2154" },
1021
+ { v: "67-33", label: "\u2154 \u2153" },
1022
+ { v: "33-33-33", label: "3" },
1023
+ { v: "25-25-25-25", label: "4" }
1024
+ ]
1025
+ },
1026
+ "r"
1027
+ )
1028
+ );
1029
+ break;
1030
+ case "tabel":
1031
+ isi.push(/* @__PURE__ */ jsx(Saklar, { nilai: !!d.kepala, ganti: (v) => ubah({ kepala: v }), label: "Baris pertama sebagai judul kolom" }, "k"));
1032
+ break;
1033
+ }
1034
+ const D = DEF[b.tipe];
1035
+ const I = D.ikon;
1036
+ return /* @__PURE__ */ jsxs("div", { className: "u-eb-atur", children: [
1037
+ /* @__PURE__ */ jsxs("div", { className: "u-eb-atur-kepala", children: [
1038
+ /* @__PURE__ */ jsx("span", { className: "u-eb-atur-ikon", children: /* @__PURE__ */ jsx(I, { "aria-hidden": true }) }),
1039
+ /* @__PURE__ */ jsxs("div", { children: [
1040
+ /* @__PURE__ */ jsx("strong", { children: D.label }),
1041
+ /* @__PURE__ */ jsx("small", { children: D.deskripsi })
1042
+ ] })
1043
+ ] }),
1044
+ isi.length ? isi : /* @__PURE__ */ jsx("p", { className: "u-eb-redup", children: "Blok ini tidak punya pengaturan tambahan." })
1045
+ ] });
1046
+ }
1047
+ var polos = (h) => h.replace(/<[^>]+>/g, "").replace(/&nbsp;/g, " ").replace(/&[a-z]+;/g, "_");
1048
+ function idFokus(b, akhir) {
1049
+ if (b.tipe === "daftar") return `${b.id}~${akhir ? Math.max(0, (b.data.item?.length ?? 1) - 1) : 0}`;
1050
+ return b.id;
1051
+ }
1052
+ function editableAktif() {
1053
+ const n = window.getSelection()?.anchorNode;
1054
+ const el = n ? n.nodeType === 1 ? n : n.parentElement : null;
1055
+ return el?.closest('[contenteditable="true"]') ?? null;
1056
+ }
1057
+ function bungkusMark() {
1058
+ const sel = window.getSelection();
1059
+ const akar = editableAktif();
1060
+ if (!sel || sel.rangeCount === 0 || sel.isCollapsed || !akar) return;
1061
+ const r = sel.getRangeAt(0);
1062
+ const m = document.createElement("mark");
1063
+ m.appendChild(r.extractContents());
1064
+ r.insertNode(m);
1065
+ akar.dispatchEvent(new Event("input", { bubbles: true }));
1066
+ }
1067
+ function bungkusKode() {
1068
+ const sel = window.getSelection();
1069
+ const akar = editableAktif();
1070
+ if (!sel || sel.rangeCount === 0 || sel.isCollapsed || !akar) return;
1071
+ const r = sel.getRangeAt(0);
1072
+ const c = document.createElement("code");
1073
+ c.textContent = r.toString();
1074
+ r.deleteContents();
1075
+ r.insertNode(c);
1076
+ akar.dispatchEvent(new Event("input", { bubbles: true }));
1077
+ }
1078
+ function FormatTeks() {
1079
+ const [tautan, setTautan] = useState(null);
1080
+ const tombol = (label, Ikon, aksi) => /* @__PURE__ */ jsx(
1081
+ "button",
1082
+ {
1083
+ type: "button",
1084
+ title: label,
1085
+ "aria-label": label,
1086
+ onMouseDown: (e2) => {
1087
+ e2.preventDefault();
1088
+ aksi();
1089
+ },
1090
+ className: "u-eb-tb",
1091
+ children: /* @__PURE__ */ jsx(Ikon, { "aria-hidden": true })
1092
+ },
1093
+ label
1094
+ );
1095
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
1096
+ tombol("Tebal (Ctrl+B)", Bold, () => document.execCommand("bold")),
1097
+ tombol("Miring (Ctrl+I)", Italic, () => document.execCommand("italic")),
1098
+ tombol("Tautan (Ctrl+K)", Link2, () => {
1099
+ const sel = window.getSelection();
1100
+ if (sel && sel.rangeCount && editableAktif()) setTautan({ r: sel.getRangeAt(0).cloneRange(), url: "https://" });
1101
+ }),
1102
+ tombol("Hapus tautan", Unlink, () => document.execCommand("unlink")),
1103
+ tombol("Sorot", Highlighter, bungkusMark),
1104
+ tombol("Kode sebaris", Code, bungkusKode),
1105
+ tautan && /* @__PURE__ */ jsxs(
1106
+ "form",
1107
+ {
1108
+ className: "u-eb-tautan-form",
1109
+ onSubmit: (e2) => {
1110
+ e2.preventDefault();
1111
+ const sel = window.getSelection();
1112
+ sel?.removeAllRanges();
1113
+ sel?.addRange(tautan.r);
1114
+ if (tautan.url.trim() && tautan.url !== "https://") {
1115
+ if (tautan.r.collapsed) document.execCommand("insertHTML", false, `<a href="${tautan.url.replace(/"/g, "%22")}">${tautan.url.replace(/</g, "&lt;")}</a>`);
1116
+ else document.execCommand("createLink", false, tautan.url.trim());
1117
+ }
1118
+ setTautan(null);
1119
+ },
1120
+ children: [
1121
+ /* @__PURE__ */ jsx(
1122
+ "input",
1123
+ {
1124
+ autoFocus: true,
1125
+ value: tautan.url,
1126
+ onChange: (e2) => setTautan({ ...tautan, url: e2.target.value }),
1127
+ onKeyDown: (e2) => e2.key === "Escape" && setTautan(null),
1128
+ className: "u-input",
1129
+ "data-size": "sm",
1130
+ "aria-label": "Alamat tautan"
1131
+ }
1132
+ ),
1133
+ /* @__PURE__ */ jsx("button", { type: "submit", className: "u-btn", "data-variant": "primary", "data-size": "sm", children: "Pasang" })
1134
+ ]
1135
+ }
1136
+ )
1137
+ ] });
1138
+ }
1139
+ function BilahBlok({ b, i, jumlah, pindah, ganti, duplikat, sisipSebelum, sisipSesudah, hapus, mulaiSeret }) {
1140
+ const D = DEF[b.tipe];
1141
+ const I = D.ikon;
1142
+ const teks = D.teks || ["daftar", "sorotan", "tabel", "akordion"].includes(b.tipe);
1143
+ const bisaUbah = BISA_UBAH.includes(b.tipe);
1144
+ const kotak = "u-eb-bilah-kotak";
1145
+ const tb = "u-eb-tb";
1146
+ return /* @__PURE__ */ jsxs("div", { className: "u-eb-bilah", contentEditable: false, onMouseDown: (e2) => e2.stopPropagation(), children: [
1147
+ /* @__PURE__ */ jsxs("div", { className: kotak, children: [
1148
+ bisaUbah ? /* @__PURE__ */ jsx(
1149
+ Menu,
1150
+ {
1151
+ align: "start",
1152
+ trigger: /* @__PURE__ */ jsx("button", { type: "button", title: `${D.label}: ubah jenis blok`, "aria-label": `${D.label}: ubah jenis blok`, className: tb, children: /* @__PURE__ */ jsx(I, { "aria-hidden": true }) }),
1153
+ items: BISA_UBAH.filter((t) => t !== b.tipe).map((t) => {
1154
+ const X2 = DEF[t].ikon;
1155
+ return { label: DEF[t].label, icon: /* @__PURE__ */ jsx(X2, {}), onSelect: () => ganti(ubahTipe(b, t)) };
1156
+ })
1157
+ }
1158
+ ) : /* @__PURE__ */ jsx("span", { className: tb, title: D.label, children: /* @__PURE__ */ jsx(I, { "aria-hidden": true }) }),
1159
+ /* @__PURE__ */ jsx("span", { draggable: true, onDragStart: mulaiSeret, title: "Seret untuk memindah", className: cn(tb, "u-eb-seret"), children: /* @__PURE__ */ jsx(GripVertical, { "aria-hidden": true }) }),
1160
+ /* @__PURE__ */ jsxs("span", { className: "u-eb-naik-turun", children: [
1161
+ /* @__PURE__ */ jsx("button", { type: "button", disabled: i === 0, onClick: () => pindah(-1), "aria-label": "Naikkan", children: /* @__PURE__ */ jsx(ChevronUp, { "aria-hidden": true }) }),
1162
+ /* @__PURE__ */ jsx("button", { type: "button", disabled: i === jumlah - 1, onClick: () => pindah(1), "aria-label": "Turunkan", children: /* @__PURE__ */ jsx(ChevronDown, { "aria-hidden": true }) })
1163
+ ] })
1164
+ ] }),
1165
+ teks && /* @__PURE__ */ jsx("div", { className: cn(kotak, "u-eb-format"), children: /* @__PURE__ */ jsx(FormatTeks, {}) }),
1166
+ /* @__PURE__ */ jsx("div", { className: kotak, children: /* @__PURE__ */ jsx(Menu, { trigger: /* @__PURE__ */ jsx("button", { type: "button", className: tb, "aria-label": "Lainnya", children: /* @__PURE__ */ jsx(MoreVertical, { "aria-hidden": true }) }), items: [
1167
+ { label: "Duplikat", icon: /* @__PURE__ */ jsx(Copy, {}), onSelect: duplikat },
1168
+ { label: "Sisip blok sebelum", icon: /* @__PURE__ */ jsx(Plus, {}), onSelect: sisipSebelum },
1169
+ { label: "Sisip blok sesudah", icon: /* @__PURE__ */ jsx(Plus, {}), onSelect: sisipSesudah },
1170
+ { type: "separator" },
1171
+ { label: "Hapus blok", icon: /* @__PURE__ */ jsx(Trash2, {}), onSelect: hapus, destructive: true }
1172
+ ] }) })
1173
+ ] });
1174
+ }
1175
+ function Kanvas({ daftar, ganti, dalamKolom }) {
1176
+ const { pilih, setPilih, setFokus, baca } = useEditor();
1177
+ const [penyisip, setPenyisip] = useState(null);
1178
+ const [seret, setSeret] = useState(null);
1179
+ const akhirRef = useRef(null);
1180
+ const fokuskan = (b, akhir) => {
1181
+ setPilih(b.id);
1182
+ if (DEF[b.tipe].teks || b.tipe === "daftar") setFokus({ id: idFokus(b, akhir), di: akhir ? "akhir" : "awal" });
1183
+ };
1184
+ const sisip = (i, bs, fokusKe = 0) => {
1185
+ const n = [...daftar];
1186
+ n.splice(i, 0, ...bs);
1187
+ ganti(n);
1188
+ if (bs[fokusKe]) fokuskan(bs[fokusKe], true);
1189
+ };
1190
+ const hapus = (i) => {
1191
+ const n = daftar.filter((_, j) => j !== i);
1192
+ ganti(n.length || dalamKolom ? n : [baru("paragraf")]);
1193
+ const sebelum = n[i - 1] ?? n[0];
1194
+ if (sebelum) fokuskan(sebelum, true);
1195
+ else setPilih(null);
1196
+ };
1197
+ const pindah = (i, a) => {
1198
+ const j = i + a;
1199
+ if (j < 0 || j >= daftar.length) return;
1200
+ const n = [...daftar];
1201
+ [n[i], n[j]] = [n[j], n[i]];
1202
+ ganti(n);
1203
+ };
1204
+ const opsUntuk = (i) => ({
1205
+ pecah: (s, d) => {
1206
+ const b = daftar[i];
1207
+ const p = baru("paragraf", { teks: d });
1208
+ const n = [...daftar];
1209
+ n.splice(i, 1, { ...b, data: { ...b.data, teks: s } }, p);
1210
+ ganti(n);
1211
+ setPilih(p.id);
1212
+ setFokus({ id: p.id, di: "awal" });
1213
+ },
1214
+ gabungAtas: (html) => {
1215
+ const b = daftar[i];
1216
+ const prev = daftar[i - 1];
1217
+ if (!prev) {
1218
+ if (b.tipe !== "paragraf" && DEF[b.tipe].teks) ganti(daftar.map((x, j) => j === i ? ubahTipe(b, "paragraf") : x));
1219
+ else if (!html && daftar.length > 1) hapus(i);
1220
+ return;
1221
+ }
1222
+ const n = daftar.filter((_, j) => j !== i);
1223
+ if (DEF[prev.tipe].teks && typeof prev.data.teks === "string") {
1224
+ const pos = polos(prev.data.teks).length;
1225
+ n[i - 1] = { ...prev, data: { ...prev.data, teks: prev.data.teks + html } };
1226
+ ganti(n);
1227
+ setPilih(prev.id);
1228
+ setFokus({ id: prev.id, di: pos });
1229
+ } else if (prev.tipe === "daftar") {
1230
+ const item = [...prev.data.item ?? [""]];
1231
+ const pos = polos(item[item.length - 1] ?? "").length;
1232
+ item[item.length - 1] = (item[item.length - 1] ?? "") + html;
1233
+ n[i - 1] = { ...prev, data: { ...prev.data, item } };
1234
+ ganti(n);
1235
+ setPilih(prev.id);
1236
+ setFokus({ id: `${prev.id}~${item.length - 1}`, di: pos });
1237
+ } else if (!html) {
1238
+ ganti(n);
1239
+ setPilih(prev.id);
1240
+ } else setPilih(prev.id);
1241
+ },
1242
+ panah: (a) => {
1243
+ const t = daftar[i + a];
1244
+ if (t) fokuskan(t, a < 0);
1245
+ },
1246
+ ubahJadi: (bs, fokusKe = 0) => {
1247
+ const n = [...daftar];
1248
+ n.splice(i, 1, ...bs);
1249
+ ganti(n);
1250
+ if (bs[fokusKe]) fokuskan(bs[fokusKe], true);
1251
+ },
1252
+ sisipSesudah: (b) => sisip(i + 1, [b]),
1253
+ hapus: () => hapus(i)
1254
+ });
1255
+ const lepas = (e2) => {
1256
+ if (!seret) return;
1257
+ e2.preventDefault();
1258
+ const { dari, ke } = seret;
1259
+ setSeret(null);
1260
+ if (ke === dari || ke === dari + 1) return;
1261
+ const n = [...daftar];
1262
+ const [b] = n.splice(dari, 1);
1263
+ n.splice(ke > dari ? ke - 1 : ke, 0, b);
1264
+ ganti(n);
1265
+ };
1266
+ return /* @__PURE__ */ jsxs("div", { className: cn("u-eb-kanvas", dalamKolom && "u-eb-kanvas-kolom"), onDragOver: (e2) => seret && e2.preventDefault(), onDrop: lepas, children: [
1267
+ daftar.map((b, i) => {
1268
+ const R = RENDER[b.tipe];
1269
+ const terpilih = pilih === b.id && !baca;
1270
+ const garisSeret = seret && seret.ke === i && seret.dari !== i && seret.dari !== i - 1;
1271
+ return /* @__PURE__ */ jsxs(
1272
+ "div",
1273
+ {
1274
+ "data-blok": b.id,
1275
+ tabIndex: -1,
1276
+ className: "u-eb-blok",
1277
+ "data-terpilih": terpilih || void 0,
1278
+ "data-baca": baca || void 0,
1279
+ "data-diseret": seret?.dari === i || void 0,
1280
+ onMouseDown: (e2) => {
1281
+ e2.stopPropagation();
1282
+ if (pilih !== b.id) setPilih(b.id);
1283
+ },
1284
+ onFocus: (e2) => {
1285
+ e2.stopPropagation();
1286
+ if (pilih !== b.id) setPilih(b.id);
1287
+ },
1288
+ onKeyDown: (e2) => {
1289
+ if (e2.target !== e2.currentTarget) return;
1290
+ if (e2.key === "Backspace" || e2.key === "Delete") {
1291
+ e2.preventDefault();
1292
+ hapus(i);
1293
+ }
1294
+ if (e2.key === "Enter") {
1295
+ e2.preventDefault();
1296
+ sisip(i + 1, [baru("paragraf")]);
1297
+ }
1298
+ },
1299
+ onDragOver: (e2) => {
1300
+ if (!seret) return;
1301
+ e2.preventDefault();
1302
+ e2.stopPropagation();
1303
+ const r = e2.currentTarget.getBoundingClientRect();
1304
+ const ke = e2.clientY < r.top + r.height / 2 ? i : i + 1;
1305
+ if (ke !== seret.ke) setSeret({ ...seret, ke });
1306
+ },
1307
+ onDragEnd: () => setSeret(null),
1308
+ children: [
1309
+ garisSeret && /* @__PURE__ */ jsx("div", { className: "u-eb-garis-seret", "data-posisi": "atas" }),
1310
+ i === daftar.length - 1 && seret && seret.ke === daftar.length && seret.dari !== i && /* @__PURE__ */ jsx("div", { className: "u-eb-garis-seret", "data-posisi": "bawah" }),
1311
+ terpilih && /* @__PURE__ */ jsx(
1312
+ BilahBlok,
1313
+ {
1314
+ b,
1315
+ i,
1316
+ jumlah: daftar.length,
1317
+ pindah: (a) => pindah(i, a),
1318
+ ganti: (x) => {
1319
+ ganti(daftar.map((y, j) => j === i ? x : y));
1320
+ fokuskan(x, true);
1321
+ },
1322
+ duplikat: () => sisip(i + 1, [salinBaru(b)]),
1323
+ sisipSebelum: () => sisip(i, [baru("paragraf")]),
1324
+ sisipSesudah: () => sisip(i + 1, [baru("paragraf")]),
1325
+ hapus: () => hapus(i),
1326
+ mulaiSeret: (e2) => {
1327
+ e2.dataTransfer.effectAllowed = "move";
1328
+ e2.dataTransfer.setData("text/plain", b.id);
1329
+ const el = e2.currentTarget.closest("[data-blok]");
1330
+ if (el) e2.dataTransfer.setDragImage(el, 20, 20);
1331
+ setSeret({ dari: i, ke: i });
1332
+ }
1333
+ }
1334
+ ),
1335
+ /* @__PURE__ */ jsx(
1336
+ R,
1337
+ {
1338
+ b,
1339
+ terpilih,
1340
+ ops: opsUntuk(i),
1341
+ ubah: (d) => ganti(daftar.map((x, j) => j === i ? { ...x, data: { ...x.data, ...d } } : x)),
1342
+ ganti: (x) => ganti(daftar.map((y, j) => j === i ? x : y))
1343
+ }
1344
+ ),
1345
+ !baca && /* @__PURE__ */ jsx(
1346
+ "button",
1347
+ {
1348
+ type: "button",
1349
+ "aria-label": "Sisipkan blok di sini",
1350
+ title: "Sisipkan blok",
1351
+ onMouseDown: (e2) => e2.stopPropagation(),
1352
+ onClick: (e2) => setPenyisip({ i: i + 1, el: e2.currentTarget }),
1353
+ className: "u-eb-sisip-antara",
1354
+ children: /* @__PURE__ */ jsx(Plus, { "aria-hidden": true })
1355
+ }
1356
+ )
1357
+ ]
1358
+ },
1359
+ b.id
1360
+ );
1361
+ }),
1362
+ !baca && /* @__PURE__ */ jsxs(
1363
+ "button",
1364
+ {
1365
+ ref: akhirRef,
1366
+ type: "button",
1367
+ onClick: (e2) => {
1368
+ const akhir = daftar[daftar.length - 1];
1369
+ if (!dalamKolom && akhir?.tipe === "paragraf" && !akhir.data.teks) setPenyisip({ i: daftar.length, el: e2.currentTarget });
1370
+ else sisip(daftar.length, [baru("paragraf")]);
1371
+ },
1372
+ className: "u-eb-tambah-akhir",
1373
+ "data-kolom": dalamKolom || void 0,
1374
+ children: [
1375
+ /* @__PURE__ */ jsx(Plus, { "aria-hidden": true }),
1376
+ dalamKolom ? "Blok" : "Tambah blok (atau ketik / di paragraf kosong)"
1377
+ ]
1378
+ }
1379
+ ),
1380
+ penyisip && /* @__PURE__ */ jsx(Penyisip, { jangkar: penyisip.el, tanpaKolom: dalamKolom, tutup: () => setPenyisip(null), pilih: (bs) => {
1381
+ const i = penyisip.i;
1382
+ setPenyisip(null);
1383
+ const akhir = daftar[i - 1];
1384
+ if (akhir && akhir.tipe === "paragraf" && !akhir.data.teks && i === daftar.length) {
1385
+ const n = [...daftar];
1386
+ n.splice(i - 1, 1, ...bs);
1387
+ ganti(n);
1388
+ fokuskan(bs[0], true);
1389
+ } else sisip(i, bs);
1390
+ } })
1391
+ ] });
1392
+ }
1393
+ function useRiwayatBlok(awal) {
1394
+ const [s, setS] = React4.useState({ kini: awal, lalu: [], nanti: [] });
1395
+ const terakhir = React4.useRef(0);
1396
+ const set = React4.useCallback((kini) => {
1397
+ const t = Date.now();
1398
+ const gabung = t - terakhir.current < 1e3;
1399
+ terakhir.current = t;
1400
+ setS((x) => ({ kini, lalu: gabung && x.lalu.length ? x.lalu : [...x.lalu, x.kini].slice(-100), nanti: [] }));
1401
+ }, []);
1402
+ const urung = React4.useCallback(() => setS((x) => x.lalu.length ? { kini: x.lalu[x.lalu.length - 1], lalu: x.lalu.slice(0, -1), nanti: [x.kini, ...x.nanti] } : x), []);
1403
+ const ulang = React4.useCallback(() => setS((x) => x.nanti.length ? { kini: x.nanti[0], lalu: [...x.lalu, x.kini], nanti: x.nanti.slice(1) } : x), []);
1404
+ const reset = React4.useCallback((b) => {
1405
+ terakhir.current = 0;
1406
+ setS({ kini: b, lalu: [], nanti: [] });
1407
+ }, []);
1408
+ return { blok: s.kini, set, urung, ulang, reset, bisaUrung: s.lalu.length > 0, bisaUlang: s.nanti.length > 0 };
1409
+ }
1410
+ var gambarKah = (m) => m.mime ? m.mime.startsWith("image/") : /\.(jpe?g|png|gif|webp|avif|svg)(\?|$)/i.test(m.url);
1411
+ function Pustaka({
1412
+ sumber,
1413
+ opsi,
1414
+ terpilih,
1415
+ ganti,
1416
+ pakai
1417
+ }) {
1418
+ const [q, setQ] = React4.useState("");
1419
+ const [kata, setKata] = React4.useState("");
1420
+ const [halaman, setHalaman] = React4.useState(1);
1421
+ const [isi, setIsi] = React4.useState([]);
1422
+ const [adaLagi, setAdaLagi] = React4.useState(false);
1423
+ const [memuat, setMemuat] = React4.useState(true);
1424
+ const [galat, setGalat] = React4.useState(null);
1425
+ React4.useEffect(() => {
1426
+ const t = setTimeout(() => {
1427
+ setKata(q.trim());
1428
+ setHalaman(1);
1429
+ }, 300);
1430
+ return () => clearTimeout(t);
1431
+ }, [q]);
1432
+ React4.useEffect(() => {
1433
+ const ctrl = new AbortController();
1434
+ setMemuat(true);
1435
+ setGalat(null);
1436
+ sumber.cari(kata, { ...opsi, halaman }, ctrl.signal).then((r) => {
1437
+ setIsi((x) => halaman === 1 ? r.data : [...x, ...r.data]);
1438
+ setAdaLagi(Boolean(r.adaLagi));
1439
+ }).catch((e2) => {
1440
+ if (!ctrl.signal.aborted) setGalat(e2 instanceof Error ? e2.message : "Daftar berkas tidak bisa dimuat.");
1441
+ }).finally(() => !ctrl.signal.aborted && setMemuat(false));
1442
+ return () => ctrl.abort();
1443
+ }, [sumber, kata, halaman, opsi]);
1444
+ const kunci = (m) => String(m.id ?? m.url);
1445
+ const dipilih = new Set(terpilih.map(kunci));
1446
+ const klik = (m) => {
1447
+ if (!opsi.banyak) return ganti(dipilih.has(kunci(m)) ? [] : [m]);
1448
+ ganti(dipilih.has(kunci(m)) ? terpilih.filter((x) => kunci(x) !== kunci(m)) : [...terpilih, m]);
1449
+ };
1450
+ return /* @__PURE__ */ jsxs("div", { className: "u-eb-pustaka", children: [
1451
+ /* @__PURE__ */ jsxs("div", { className: "u-eb-pustaka-cari", children: [
1452
+ /* @__PURE__ */ jsx(Search, { "aria-hidden": true }),
1453
+ /* @__PURE__ */ jsx(
1454
+ "input",
1455
+ {
1456
+ type: "search",
1457
+ value: q,
1458
+ onChange: (e2) => setQ(e2.target.value),
1459
+ placeholder: opsi.jenis === "dokumen" ? "Cari nama berkas" : "Cari nama atau keterangan foto",
1460
+ "aria-label": "Cari berkas",
1461
+ autoFocus: true
1462
+ }
1463
+ )
1464
+ ] }),
1465
+ galat ? /* @__PURE__ */ jsx("p", { className: "u-field-error", children: galat }) : !memuat && isi.length === 0 ? /* @__PURE__ */ jsx("p", { className: "u-eb-kosong", children: kata ? `Tidak ada berkas \u201C${kata}\u201D.` : "Belum ada berkas di sistem. Unggah dari tab Unggah." }) : /* @__PURE__ */ jsxs("div", { className: "u-eb-pustaka-kisi", role: "listbox", "aria-multiselectable": opsi.banyak || void 0, "aria-label": "Berkas di sistem", "data-dokumen": opsi.jenis === "dokumen" || void 0, children: [
1466
+ isi.map((m) => {
1467
+ const on = dipilih.has(kunci(m));
1468
+ const g = gambarKah(m);
1469
+ return /* @__PURE__ */ jsxs(
1470
+ "button",
1471
+ {
1472
+ type: "button",
1473
+ role: "option",
1474
+ "aria-selected": on,
1475
+ className: "u-eb-pustaka-item",
1476
+ title: m.judul || m.nama || m.url,
1477
+ onClick: () => klik(m),
1478
+ onDoubleClick: () => pakai(opsi.banyak ? on ? terpilih : [...terpilih, m] : [m]),
1479
+ children: [
1480
+ g ? /* @__PURE__ */ jsx("img", { src: m.pratinjau ?? m.url, alt: m.alt ?? "", loading: "lazy" }) : /* @__PURE__ */ jsxs("span", { className: "u-eb-pustaka-berkas", children: [
1481
+ /* @__PURE__ */ jsx(FileText, { "aria-hidden": true }),
1482
+ /* @__PURE__ */ jsx("span", { children: m.judul || m.nama || m.url.split("/").pop() }),
1483
+ m.ukuran ? /* @__PURE__ */ jsx("small", { children: formatBytes(m.ukuran) }) : null
1484
+ ] }),
1485
+ on && /* @__PURE__ */ jsx("span", { className: "u-eb-pustaka-centang", "aria-hidden": true, children: /* @__PURE__ */ jsx(Check, {}) })
1486
+ ]
1487
+ },
1488
+ kunci(m)
1489
+ );
1490
+ }),
1491
+ memuat && Array.from({ length: isi.length ? 3 : 8 }, (_, i) => /* @__PURE__ */ jsx("span", { className: "u-eb-pustaka-item u-skeleton", "aria-hidden": true }, `m${i}`))
1492
+ ] }),
1493
+ adaLagi && !memuat && /* @__PURE__ */ jsx(Button, { variant: "ghost", size: "sm", onClick: () => setHalaman((h) => h + 1), children: "Muat lebih banyak" })
1494
+ ] });
1495
+ }
1496
+ function usePemilihMediaBawaan(unggah, sumber) {
1497
+ const [minta, setMinta] = React4.useState(null);
1498
+ const [tab, setTab] = React4.useState("tautan");
1499
+ const [terpilih, setTerpilih] = React4.useState([]);
1500
+ const [url, setUrl] = React4.useState("");
1501
+ const [alt, setAlt] = React4.useState("");
1502
+ const [sibuk, setSibuk] = React4.useState(false);
1503
+ const [galat, setGalat] = React4.useState(null);
1504
+ const masuk = React4.useRef(null);
1505
+ const pilihMedia = React4.useCallback(
1506
+ (opsi = {}) => new Promise((selesai) => {
1507
+ setUrl("");
1508
+ setAlt("");
1509
+ setGalat(null);
1510
+ setTerpilih([]);
1511
+ setTab(sumber ? "pustaka" : unggah ? "unggah" : "tautan");
1512
+ setMinta({ opsi, selesai });
1513
+ }),
1514
+ [sumber, unggah]
1515
+ );
1516
+ const tutup = (m) => {
1517
+ minta?.selesai(m);
1518
+ setMinta(null);
1519
+ };
1520
+ const gambar = minta?.opsi.jenis !== "dokumen";
1521
+ const opsiTetap = React4.useMemo(() => minta?.opsi ?? {}, [minta]);
1522
+ const tabs = [
1523
+ ...sumber ? [{ value: "pustaka", label: sumber.nama ?? "Pustaka" }] : [],
1524
+ ...unggah ? [{ value: "unggah", label: "Unggah" }] : [],
1525
+ { value: "tautan", label: "Alamat" }
1526
+ ];
1527
+ const pakaiAlamat = () => tutup([{ url: url.trim(), alt, nama: decodeURIComponent(url.split("?")[0].split("/").pop() ?? "") }]);
1528
+ const dialog = /* @__PURE__ */ jsx(
1529
+ Dialog,
1530
+ {
1531
+ open: Boolean(minta),
1532
+ onOpenChange: (o) => !o && tutup(null),
1533
+ title: gambar ? minta?.opsi.banyak ? "Pilih foto" : "Pilih gambar" : "Pilih berkas",
1534
+ description: sumber ? "Pilih berkas yang sudah ada di sistem, unggah yang baru, atau tempel alamatnya." : unggah ? "Unggah dari perangkat atau tempel alamat yang sudah ada." : "Tempel alamat gambar atau berkas.",
1535
+ size: tab === "pustaka" ? "lg" : "sm",
1536
+ footer: /* @__PURE__ */ jsxs(Fragment, { children: [
1537
+ /* @__PURE__ */ jsx(Button, { variant: "ghost", onClick: () => tutup(null), children: "Batal" }),
1538
+ tab === "pustaka" && /* @__PURE__ */ jsxs(Button, { disabled: !terpilih.length, onClick: () => tutup(terpilih), children: [
1539
+ /* @__PURE__ */ jsx(Check, { "aria-hidden": true }),
1540
+ terpilih.length > 1 ? `Pakai ${terpilih.length} berkas` : "Pakai berkas ini"
1541
+ ] }),
1542
+ tab === "tautan" && /* @__PURE__ */ jsxs(Button, { disabled: !/^(https?:\/\/|\/)/.test(url.trim()), onClick: pakaiAlamat, children: [
1543
+ /* @__PURE__ */ jsx(Link2, { "aria-hidden": true }),
1544
+ "Pakai alamat ini"
1545
+ ] })
1546
+ ] }),
1547
+ children: /* @__PURE__ */ jsxs("div", { className: "u-eb-media", children: [
1548
+ tabs.length > 1 && /* @__PURE__ */ jsx(SegmentedControl, { "aria-label": "Sumber berkas", fullWidth: true, value: tab, onValueChange: setTab, options: tabs }),
1549
+ tab === "pustaka" && sumber && minta && /* @__PURE__ */ jsx(Pustaka, { sumber, opsi: opsiTetap, terpilih, ganti: setTerpilih, pakai: tutup }),
1550
+ tab === "unggah" && unggah && /* @__PURE__ */ jsxs(Fragment, { children: [
1551
+ /* @__PURE__ */ jsx(
1552
+ "input",
1553
+ {
1554
+ ref: masuk,
1555
+ type: "file",
1556
+ hidden: true,
1557
+ multiple: minta?.opsi.banyak,
1558
+ accept: gambar ? "image/*" : void 0,
1559
+ onChange: async (e2) => {
1560
+ const files = Array.from(e2.target.files ?? []);
1561
+ e2.target.value = "";
1562
+ if (!files.length || !minta) return;
1563
+ setSibuk(true);
1564
+ setGalat(null);
1565
+ try {
1566
+ const hasil = [];
1567
+ for (const f of files) hasil.push(await unggah(f, minta.opsi));
1568
+ tutup(hasil);
1569
+ } catch (x) {
1570
+ setGalat(x instanceof Error ? x.message : "Unggah gagal. Coba lagi.");
1571
+ } finally {
1572
+ setSibuk(false);
1573
+ }
1574
+ }
1575
+ }
1576
+ ),
1577
+ /* @__PURE__ */ jsxs("button", { type: "button", className: "u-eb-media-unggah", onClick: () => masuk.current?.click(), disabled: sibuk, children: [
1578
+ gambar ? /* @__PURE__ */ jsx(ImagePlus, { "aria-hidden": true }) : /* @__PURE__ */ jsx(Upload, { "aria-hidden": true }),
1579
+ /* @__PURE__ */ jsx("strong", { children: sibuk ? "Mengunggah\u2026" : gambar ? "Unggah foto" : "Unggah berkas" }),
1580
+ /* @__PURE__ */ jsx("small", { children: gambar ? "JPG, PNG, atau WebP; lebar ideal 1600 px." : "PDF atau dokumen Office." })
1581
+ ] }),
1582
+ galat && /* @__PURE__ */ jsx("p", { className: "u-field-error", children: galat })
1583
+ ] }),
1584
+ tab === "tautan" && /* @__PURE__ */ jsxs(Fragment, { children: [
1585
+ /* @__PURE__ */ jsx(Field, { label: "Alamat (URL)", children: /* @__PURE__ */ jsx(Input, { value: url, onChange: (e2) => setUrl(e2.target.value), placeholder: "https://\u2026" }) }),
1586
+ gambar && /* @__PURE__ */ jsx(Field, { label: "Teks alternatif", description: "Gambarkan isi foto untuk pembaca layar.", children: /* @__PURE__ */ jsx(Input, { value: alt, onChange: (e2) => setAlt(e2.target.value) }) })
1587
+ ] })
1588
+ ] })
1589
+ }
1590
+ );
1591
+ return { pilihMedia, dialog };
1592
+ }
1593
+ function EditorBlok({ blok, set, urung, ulang, pilih: pilihProp, setPilih: setPilihProp, pilihMedia: pilihMediaProp, unggah, sumberMedia, pola, kepala, baca, className }) {
1594
+ const [fokus, setFokus] = React4.useState(null);
1595
+ const [pilihSendiri, setPilihSendiri] = React4.useState(null);
1596
+ const pilih = pilihProp !== void 0 ? pilihProp : pilihSendiri;
1597
+ const setPilih = setPilihProp ?? setPilihSendiri;
1598
+ const bawaan = usePemilihMediaBawaan(unggah, sumberMedia);
1599
+ const pilihMedia = pilihMediaProp ?? bawaan.pilihMedia;
1600
+ const akar = React4.useRef(null);
1601
+ React4.useEffect(() => {
1602
+ const tombol = (e2) => {
1603
+ if (!akar.current?.contains(document.activeElement) && document.activeElement !== document.body) return;
1604
+ const mod = e2.ctrlKey || e2.metaKey;
1605
+ if (mod && e2.key.toLowerCase() === "z") {
1606
+ e2.preventDefault();
1607
+ if (e2.shiftKey) ulang?.();
1608
+ else urung?.();
1609
+ } else if (mod && e2.key.toLowerCase() === "y") {
1610
+ e2.preventDefault();
1611
+ ulang?.();
1612
+ } else if (e2.key === "Escape" && pilih) {
1613
+ setPilih(null);
1614
+ }
1615
+ };
1616
+ document.addEventListener("keydown", tombol);
1617
+ return () => document.removeEventListener("keydown", tombol);
1618
+ }, [urung, ulang, pilih, setPilih]);
1619
+ const ctx = React4.useMemo(() => ({ pilih, setPilih, fokus, setFokus, pilihMedia, pola, baca: Boolean(baca) }), [pilih, setPilih, fokus, pilihMedia, pola, baca]);
1620
+ return /* @__PURE__ */ jsxs(EditorCtx.Provider, { value: ctx, children: [
1621
+ /* @__PURE__ */ jsxs(
1622
+ "div",
1623
+ {
1624
+ ref: akar,
1625
+ className: cn("ub-konten ub-editor u-eb", className),
1626
+ onMouseDown: (e2) => {
1627
+ if (e2.target === e2.currentTarget) setPilih(null);
1628
+ },
1629
+ children: [
1630
+ kepala,
1631
+ /* @__PURE__ */ jsx(Kanvas, { daftar: blok.length ? blok : [], ganti: set })
1632
+ ]
1633
+ }
1634
+ ),
1635
+ !pilihMediaProp && bawaan.dialog
1636
+ ] });
1637
+ }
1638
+
1639
+ // src/editor/render.ts
1640
+ var TIPE_BLOK = ["paragraf", "judul", "daftar", "kutipan", "gambar", "galeri", "video", "tombol", "pemisah", "spasi", "kolom", "tabel", "kode", "sorotan", "berkas", "akordion", "peta"];
1641
+ var MAKS_BLOK = 600;
1642
+ var MAKS_JSON = 2e6;
1643
+ var GalatBlok = class extends Error {
1644
+ constructor() {
1645
+ super(...arguments);
1646
+ this.field = "blok";
1647
+ }
1648
+ };
1649
+ function validasiBlok(blok) {
1650
+ if (typeof blok === "string") {
1651
+ if (blok.length > MAKS_JSON) throw new GalatBlok("isi terlalu besar");
1652
+ try {
1653
+ blok = JSON.parse(blok);
1654
+ } catch {
1655
+ throw new GalatBlok("harus berupa daftar blok");
1656
+ }
1657
+ }
1658
+ if (!Array.isArray(blok)) throw new GalatBlok("harus berupa daftar blok");
1659
+ let hitung = 0;
1660
+ const jalan = (daftar, dalam) => {
1661
+ for (const b of daftar) {
1662
+ if (!b || typeof b !== "object") continue;
1663
+ if (++hitung > MAKS_BLOK) throw new GalatBlok(`maksimal ${MAKS_BLOK} blok`);
1664
+ const tipe = String(b.tipe ?? "");
1665
+ if (!TIPE_BLOK.includes(tipe)) throw new GalatBlok(`tipe blok tidak dikenal: ${tipe.slice(0, 30)}`);
1666
+ if (tipe === "kolom") {
1667
+ if (dalam > 0) throw new GalatBlok("blok kolom tidak boleh di dalam kolom");
1668
+ (b.anak ?? []).slice(0, 4).forEach((k) => Array.isArray(k) && jalan(k, dalam + 1));
1669
+ }
1670
+ }
1671
+ };
1672
+ jalan(blok, 0);
1673
+ if (JSON.stringify(blok).length > MAKS_JSON) throw new GalatBlok("isi terlalu besar");
1674
+ return blok;
1675
+ }
1676
+ var e = (s) => s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;");
1677
+ var polos2 = (h) => h.replace(/<[^>]*>/g, "");
1678
+ var kosong = (h) => polos2(h).replace(/&nbsp;/g, " ").trim() === "";
1679
+ var SEBARIS = /* @__PURE__ */ new Set(["STRONG", "EM", "B", "I", "A", "MARK", "CODE", "BR", "SUB", "SUP", "U", "S"]);
1680
+ function saringSebaris(html) {
1681
+ if (!html) return "";
1682
+ if (typeof DOMParser === "undefined") return e(polos2(html));
1683
+ const doc = new DOMParser().parseFromString(`<div>${html}</div>`, "text/html");
1684
+ const akar = doc.body.firstElementChild;
1685
+ const jalan = (el) => {
1686
+ Array.from(el.children).forEach((n) => {
1687
+ jalan(n);
1688
+ if (!SEBARIS.has(n.tagName)) {
1689
+ n.replaceWith(...Array.from(n.childNodes));
1690
+ return;
1691
+ }
1692
+ Array.from(n.attributes).forEach((a) => {
1693
+ if (n.tagName === "A" && a.name === "href" && urlAman(a.value)) return;
1694
+ n.removeAttribute(a.name);
1695
+ });
1696
+ });
1697
+ };
1698
+ jalan(akar);
1699
+ return akar.innerHTML;
1700
+ }
1701
+ function urlAman(url, gambar = false) {
1702
+ const u = url.trim();
1703
+ if (!u || u.length > 2e3) return false;
1704
+ if (/^(https?:)?\/\//i.test(u) || /^(mailto|tel):/i.test(u)) return true;
1705
+ if (gambar && /^data:image\/(png|jpe?g|gif|webp);base64,/i.test(u)) return true;
1706
+ return /^[/#?.]/.test(u) || !/^[a-z][a-z0-9+.-]*:/i.test(u);
1707
+ }
1708
+ function embedVideo2(url) {
1709
+ const u = url.trim();
1710
+ const yt = u.match(/^https?:\/\/(?:www\.|m\.)?(?:youtube\.com\/(?:watch\?(?:.*&)?v=|embed\/|shorts\/|live\/)|youtu\.be\/)([A-Za-z0-9_-]{11})/);
1711
+ if (yt) return `https://www.youtube-nocookie.com/embed/${yt[1]}`;
1712
+ const vm = u.match(/^https?:\/\/(?:www\.|player\.)?vimeo\.com\/(?:video\/)?(\d{5,12})/);
1713
+ return vm ? `https://player.vimeo.com/video/${vm[1]}` : null;
1714
+ }
1715
+ function jangkar(html) {
1716
+ const t = polos2(html).replace(/&nbsp;/g, " ").trim().toLowerCase().replace(/[^a-z0-9]+/g, "-");
1717
+ return t.slice(0, 60).replace(/^-+|-+$/g, "") || "bagian";
1718
+ }
1719
+ var ukuran = (b) => b >= 1048576 ? `${(b / 1048576).toFixed(1).replace(".", ",")} MB` : `${Math.max(1, Math.round(b / 1024))} KB`;
1720
+ var keterangan = (k) => kosong(k) ? "" : `<figcaption>${saringSebaris(k)}</figcaption>`;
1721
+ function satu(b) {
1722
+ const d = b.data ?? {};
1723
+ const t = (k) => String(d[k] ?? "");
1724
+ const rata = () => d.rata === "tengah" || d.rata === "kanan" ? ` ub-rata-${d.rata}` : "";
1725
+ switch (b.tipe) {
1726
+ case "paragraf":
1727
+ return kosong(t("teks")) ? "" : `<p class="ub-paragraf${d.besar ? " ub-pembuka" : ""}${rata()}">${saringSebaris(t("teks"))}</p>`;
1728
+ case "judul": {
1729
+ const n = Math.max(2, Math.min(4, Number(d.tingkat) || 2));
1730
+ return kosong(t("teks")) ? "" : `<h${n} id="${e(jangkar(t("teks")))}" class="ub-judul${rata()}">${saringSebaris(t("teks"))}</h${n}>`;
1731
+ }
1732
+ case "daftar": {
1733
+ const tag = d.gaya === "ol" ? "ol" : "ul";
1734
+ const li = (Array.isArray(d.item) ? d.item : []).filter((x) => typeof x === "string" && !kosong(x)).map((x) => `<li>${saringSebaris(x)}</li>`).join("");
1735
+ return li ? `<${tag} class="ub-daftar">${li}</${tag}>` : "";
1736
+ }
1737
+ case "kutipan": {
1738
+ if (kosong(t("teks"))) return "";
1739
+ const sumber = t("sumber") ? `<cite class="ub-kutipan-sumber">${e(polos2(t("sumber")))}</cite>` : "";
1740
+ return `<blockquote class="ub-kutipan${d.gaya === "sorot" ? " ub-kutipan-sorot" : ""}"><p>${saringSebaris(t("teks"))}</p>${sumber}</blockquote>`;
1741
+ }
1742
+ case "gambar": {
1743
+ if (!urlAman(t("url"), true)) return "";
1744
+ let img = `<img src="${e(t("url").trim())}" alt="${e(polos2(t("alt")))}" loading="lazy">`;
1745
+ if (urlAman(t("tautan"))) img = `<a href="${e(t("tautan").trim())}">${img}</a>`;
1746
+ const lebar = d.lebar === "lebar" || d.lebar === "penuh" ? ` ub-lebar-${d.lebar}` : "";
1747
+ return `<figure class="ub-gambar${lebar}${rata()}">${img}${keterangan(t("keterangan"))}</figure>`;
1748
+ }
1749
+ case "galeri": {
1750
+ const kolom = Math.max(2, Math.min(4, Number(d.kolom) || 3));
1751
+ const isi = (Array.isArray(d.gambar) ? d.gambar : []).filter((g) => g && urlAman(String(g.url ?? ""), true)).map((g) => `<figure class="ub-galeri-item"><img src="${e(String(g.url).trim())}" alt="${e(polos2(String(g.alt ?? "")))}" loading="lazy">${keterangan(String(g.keterangan ?? ""))}</figure>`).join("");
1752
+ return isi ? `<div class="ub-galeri ub-kolom-${kolom}">${isi}</div>` : "";
1753
+ }
1754
+ case "video": {
1755
+ const src = embedVideo2(t("url"));
1756
+ return src ? `<figure class="ub-video"><div class="ub-video-bingkai"><iframe src="${e(src)}" title="${e(polos2(t("keterangan")) || "Video")}" allowfullscreen loading="lazy"></iframe></div>${keterangan(t("keterangan"))}</figure>` : "";
1757
+ }
1758
+ case "tombol": {
1759
+ const isi = (Array.isArray(d.tombol) ? d.tombol : []).filter((x) => x && urlAman(String(x.url ?? "")) && polos2(String(x.label ?? "")).trim()).map((x) => `<a class="ub-tombol ub-tombol-${x.gaya === "garis" ? "garis" : "utama"}" href="${e(String(x.url).trim())}">${e(polos2(String(x.label)).trim())}</a>`).join("");
1760
+ return isi ? `<div class="ub-tombol-grup${rata()}">${isi}</div>` : "";
1761
+ }
1762
+ case "pemisah":
1763
+ return `<hr class="ub-pemisah${d.gaya === "titik" ? " ub-pemisah-titik" : ""}">`;
1764
+ case "spasi":
1765
+ return `<div class="ub-spasi ub-spasi-${d.ukuran === "kecil" || d.ukuran === "besar" ? d.ukuran : "sedang"}"></div>`;
1766
+ case "kolom": {
1767
+ const rasio = d.rasio in RASIO ? d.rasio : "50-50";
1768
+ const isi = (b.anak ?? []).map((k) => `<div class="ub-kolom">${(k ?? []).map(satu).join("")}</div>`).join("");
1769
+ return `<div class="ub-kolom-grup ub-rasio-${rasio}">${isi}</div>`;
1770
+ }
1771
+ case "tabel": {
1772
+ const baris = (Array.isArray(d.baris) ? d.baris : []).filter(Array.isArray);
1773
+ if (!baris.length) return "";
1774
+ const kepala = Boolean(d.kepala);
1775
+ let h = '<figure class="ub-tabel"><table>';
1776
+ baris.forEach((r, i) => {
1777
+ const sel = kepala && i === 0 ? "th" : "td";
1778
+ const tr = r.map((c) => `<${sel}${sel === "th" ? ' scope="col"' : ""}>${typeof c === "string" ? saringSebaris(c) : ""}</${sel}>`).join("");
1779
+ h += kepala && i === 0 ? `<thead><tr>${tr}</tr></thead><tbody>` : `<tr>${tr}</tr>`;
1780
+ });
1781
+ return `${h}${kepala ? "</tbody>" : ""}</table>${keterangan(t("keterangan"))}</figure>`;
1782
+ }
1783
+ case "kode":
1784
+ return t("teks") ? `<pre class="ub-kode"><code>${e(t("teks"))}</code></pre>` : "";
1785
+ case "sorotan": {
1786
+ const gaya = ["sukses", "peringatan", "bahaya"].includes(d.gaya) ? d.gaya : "info";
1787
+ const judul = t("judul") ? `<strong class="ub-sorotan-judul">${e(polos2(t("judul")))}</strong>` : "";
1788
+ return `<div class="ub-sorotan ub-sorotan-${gaya}">${judul}<div class="ub-sorotan-isi">${saringSebaris(t("teks"))}</div></div>`;
1789
+ }
1790
+ case "berkas": {
1791
+ if (!urlAman(t("url"))) return "";
1792
+ const nama = polos2(t("nama")).trim() || decodeURIComponent(t("url").split("?")[0].split("/").pop() ?? "berkas");
1793
+ const uk = Number(d.ukuran) > 0 ? `<small class="ub-berkas-ukuran">${ukuran(Number(d.ukuran))}</small>` : "";
1794
+ return `<div class="ub-berkas"><a href="${e(t("url").trim())}" target="_blank">${e(nama)}</a>${uk}</div>`;
1795
+ }
1796
+ case "akordion": {
1797
+ const isi = (Array.isArray(d.item) ? d.item : []).filter((x) => x && String(x.judul ?? "").trim()).map((x) => `<details class="ub-akordion-item"><summary>${e(polos2(String(x.judul)))}</summary><div>${saringSebaris(String(x.isi ?? ""))}</div></details>`).join("");
1798
+ return isi ? `<div class="ub-akordion">${isi}</div>` : "";
1799
+ }
1800
+ case "peta":
1801
+ return /^https:\/\/(www\.)?google\.com\/maps\/embed\?[^"'<>\s]+$/i.test(t("url")) ? `<figure class="ub-peta"><div class="ub-video-bingkai"><iframe src="${e(t("url"))}" title="Peta lokasi" loading="lazy"></iframe></div></figure>` : "";
1802
+ }
1803
+ return "";
1804
+ }
1805
+ function blokKeHtml(blok) {
1806
+ return blok.map(satu).join("");
1807
+ }
1808
+ function daftarIsiBlok(blok) {
1809
+ const out = [];
1810
+ const jalan = (d) => d.forEach((b) => {
1811
+ if (b.tipe === "judul" && !kosong(String(b.data.teks ?? ""))) out.push({ id: jangkar(String(b.data.teks)), teks: polos2(String(b.data.teks)), tingkat: Math.max(2, Math.min(4, Number(b.data.tingkat) || 2)) });
1812
+ b.anak?.forEach(jalan);
1813
+ });
1814
+ jalan(blok);
1815
+ return out;
1816
+ }
1817
+ function waktuBaca(jumlahKata) {
1818
+ return Math.max(1, Math.round(jumlahKata / 200));
1819
+ }
1820
+ function cekTerbitBerita(n, minKata = 80) {
1821
+ const kata = hitungKata(n.blok);
1822
+ const tanpaAlt = cariSemua(n.blok, (b) => b.tipe === "gambar" && Boolean(b.data.url) && !String(b.data.alt ?? "").trim()).length;
1823
+ const c = [
1824
+ { ok: Boolean(n.judul.trim()), teks: "Judul sudah diisi", wajib: true },
1825
+ { ok: kata >= minKata, teks: `Isi cukup panjang (${kata} kata, saran minimal ${minKata})` },
1826
+ { ok: Boolean(n.ringkasan?.trim()), teks: "Ringkasan diisi (kalau kosong, diambil dari paragraf pertama)" }
1827
+ ];
1828
+ if (tanpaAlt) c.push({ ok: false, teks: `${tanpaAlt} gambar belum punya teks alternatif` });
1829
+ return c;
1830
+ }
1831
+ function TampilBlok({ blok, className }) {
1832
+ const html = React4.useMemo(() => blokKeHtml(blok), [blok]);
1833
+ return /* @__PURE__ */ jsx("div", { className: cn("ub-konten", className), dangerouslySetInnerHTML: { __html: html } });
1834
+ }
1835
+ function JudulOtomatis({ nilai, ganti, placeholder, className, label }) {
1836
+ const ref = React4.useRef(null);
1837
+ const ukur = React4.useCallback(() => {
1838
+ const el = ref.current;
1839
+ if (!el) return;
1840
+ el.style.height = "auto";
1841
+ el.style.height = `${el.scrollHeight}px`;
1842
+ }, []);
1843
+ React4.useLayoutEffect(ukur, [nilai, ukur]);
1844
+ React4.useEffect(() => {
1845
+ const el = ref.current;
1846
+ if (!el || typeof ResizeObserver === "undefined") return;
1847
+ let lebar = el.clientWidth;
1848
+ const ro = new ResizeObserver(() => {
1849
+ if (el.clientWidth !== lebar) {
1850
+ lebar = el.clientWidth;
1851
+ ukur();
1852
+ }
1853
+ });
1854
+ ro.observe(el);
1855
+ return () => ro.disconnect();
1856
+ }, [ukur]);
1857
+ return /* @__PURE__ */ jsx("textarea", { ref, rows: 1, className, value: nilai, placeholder, "aria-label": label, onChange: (e2) => ganti(e2.target.value.replace(/\n/g, " ")) });
1858
+ }
1859
+ function EditorBerita({
1860
+ nilaiAwal,
1861
+ onChange,
1862
+ aksi,
1863
+ panelDokumen,
1864
+ cekTambahan,
1865
+ minKata = 80,
1866
+ pilihMedia,
1867
+ unggah,
1868
+ sumberMedia,
1869
+ pola,
1870
+ status,
1871
+ tanpaRingkasan,
1872
+ placeholderJudul = "Tulis judul berita",
1873
+ tinggi,
1874
+ className
1875
+ }) {
1876
+ const [judul, setJudul] = React4.useState(nilaiAwal?.judul ?? "");
1877
+ const [ringkasan, setRingkasan] = React4.useState(nilaiAwal?.ringkasan ?? "");
1878
+ const r = useRiwayatBlok(nilaiAwal?.blok?.length ? nilaiAwal.blok : [baru("paragraf")]);
1879
+ const [pilih, setPilih] = React4.useState(null);
1880
+ const [tab, setTab] = React4.useState("dokumen");
1881
+ const [panel, setPanel] = React4.useState(true);
1882
+ const [pratinjau, setPratinjau] = React4.useState(false);
1883
+ const [cekBuka, setCekBuka] = React4.useState(false);
1884
+ const nilai = React4.useMemo(() => ({ judul, ringkasan: tanpaRingkasan ? void 0 : ringkasan, blok: r.blok }), [judul, ringkasan, r.blok, tanpaRingkasan]);
1885
+ const onChangeRef = React4.useRef(onChange);
1886
+ onChangeRef.current = onChange;
1887
+ const pertama = React4.useRef(true);
1888
+ React4.useEffect(() => {
1889
+ if (pertama.current) {
1890
+ pertama.current = false;
1891
+ return;
1892
+ }
1893
+ onChangeRef.current?.(nilai);
1894
+ }, [nilai]);
1895
+ React4.useEffect(() => {
1896
+ if (pilih) setTab("blok");
1897
+ }, [pilih]);
1898
+ const kata = hitungKata(r.blok);
1899
+ const cek = React4.useMemo(() => [...cekTerbitBerita(nilai, minKata), ...cekTambahan?.(nilai) ?? []], [nilai, minKata, cekTambahan]);
1900
+ const blokPilih = pilih ? cariBlok(r.blok, pilih) : null;
1901
+ const isi = daftarIsiBlok(r.blok);
1902
+ const belum = cek.filter((c) => !c.ok).length;
1903
+ const kepala = /* @__PURE__ */ jsxs("div", { className: "u-eb-kepala", onMouseDown: (e2) => e2.stopPropagation(), children: [
1904
+ /* @__PURE__ */ jsx(JudulOtomatis, { nilai: judul, ganti: setJudul, placeholder: placeholderJudul, className: "u-eb-judul", label: "Judul" }),
1905
+ !tanpaRingkasan && /* @__PURE__ */ jsx(JudulOtomatis, { nilai: ringkasan, ganti: setRingkasan, placeholder: "Ringkasan singkat (tampil di kartu berita dan mesin pencari)", className: "u-eb-ringkasan", label: "Ringkasan" })
1906
+ ] });
1907
+ return /* @__PURE__ */ jsxs("div", { className: cn("u-eb-berita", className), "data-panel": panel || void 0, "data-tinggi": tinggi !== void 0 || void 0, style: tinggi !== void 0 ? { height: tinggi } : void 0, children: [
1908
+ /* @__PURE__ */ jsxs("div", { className: "u-eb-atas", role: "toolbar", "aria-label": "Alat editor", children: [
1909
+ /* @__PURE__ */ jsxs("div", { className: "u-eb-atas-kiri", children: [
1910
+ /* @__PURE__ */ jsx(Tooltip, { content: "Urungkan", shortcut: "Ctrl+Z", children: /* @__PURE__ */ jsx(Button, { variant: "ghost", size: "sm", iconOnly: true, "aria-label": "Urungkan", onClick: r.urung, disabled: !r.bisaUrung || pratinjau, children: /* @__PURE__ */ jsx(Undo2, {}) }) }),
1911
+ /* @__PURE__ */ jsx(Tooltip, { content: "Ulangi", shortcut: "Ctrl+Shift+Z", children: /* @__PURE__ */ jsx(Button, { variant: "ghost", size: "sm", iconOnly: true, "aria-label": "Ulangi", onClick: r.ulang, disabled: !r.bisaUlang || pratinjau, children: /* @__PURE__ */ jsx(Redo2, {}) }) }),
1912
+ /* @__PURE__ */ jsxs("span", { className: "u-eb-statistik", children: [
1913
+ kata,
1914
+ " kata \xB7 ",
1915
+ waktuBaca(kata),
1916
+ " menit baca"
1917
+ ] }),
1918
+ status && /* @__PURE__ */ jsx("span", { className: "u-eb-status", children: status })
1919
+ ] }),
1920
+ /* @__PURE__ */ jsxs("div", { className: "u-eb-atas-kanan", children: [
1921
+ /* @__PURE__ */ jsxs(Button, { variant: pratinjau ? "soft" : "ghost", size: "sm", onClick: () => setPratinjau((x) => !x), "aria-pressed": pratinjau, "aria-label": pratinjau ? "Sunting" : "Pratinjau", children: [
1922
+ pratinjau ? /* @__PURE__ */ jsx(PenLine, {}) : /* @__PURE__ */ jsx(Eye, {}),
1923
+ /* @__PURE__ */ jsx("span", { className: "u-eb-label", children: pratinjau ? "Sunting" : "Pratinjau" })
1924
+ ] }),
1925
+ /* @__PURE__ */ jsxs(Button, { variant: "ghost", size: "sm", onClick: () => setCekBuka(true), "aria-label": belum ? `Cek terbit, ${belum} belum lolos` : "Cek terbit", children: [
1926
+ belum ? /* @__PURE__ */ jsx(Info, {}) : /* @__PURE__ */ jsx(CheckCircle2, {}),
1927
+ /* @__PURE__ */ jsx("span", { className: "u-eb-label", children: "Cek terbit" }),
1928
+ belum ? ` (${belum})` : ""
1929
+ ] }),
1930
+ /* @__PURE__ */ jsx(Tooltip, { content: panel ? "Tutup panel" : "Buka panel", children: /* @__PURE__ */ jsx(Button, { variant: panel ? "soft" : "ghost", size: "sm", iconOnly: true, "aria-label": "Panel pengaturan", "aria-pressed": panel, onClick: () => setPanel((x) => !x), children: /* @__PURE__ */ jsx(PanelRight, {}) }) }),
1931
+ aksi?.(nilai, cek)
1932
+ ] })
1933
+ ] }),
1934
+ /* @__PURE__ */ jsxs("div", { className: "u-eb-tubuh", children: [
1935
+ /* @__PURE__ */ jsx("div", { className: "u-eb-lembar", children: pratinjau ? /* @__PURE__ */ jsxs("article", { className: "u-eb-pratinjau", children: [
1936
+ /* @__PURE__ */ jsx("h1", { className: "u-eb-judul", children: judul || "Tanpa judul" }),
1937
+ ringkasan && !tanpaRingkasan && /* @__PURE__ */ jsx("p", { className: "u-eb-ringkasan", children: ringkasan }),
1938
+ /* @__PURE__ */ jsx(TampilBlok, { blok: r.blok })
1939
+ ] }) : /* @__PURE__ */ jsx(EditorBlok, { blok: r.blok, set: r.set, urung: r.urung, ulang: r.ulang, pilih, setPilih, pilihMedia, unggah, sumberMedia, pola, kepala }) }),
1940
+ panel && /* @__PURE__ */ jsxs("aside", { className: "u-eb-panel", "aria-label": "Pengaturan", children: [
1941
+ /* @__PURE__ */ jsxs("div", { className: "u-eb-panel-tab", role: "tablist", children: [
1942
+ /* @__PURE__ */ jsx("button", { type: "button", role: "tab", "aria-selected": tab === "dokumen", onClick: () => setTab("dokumen"), children: "Dokumen" }),
1943
+ /* @__PURE__ */ jsx("button", { type: "button", role: "tab", "aria-selected": tab === "blok", onClick: () => setTab("blok"), children: "Blok" })
1944
+ ] }),
1945
+ /* @__PURE__ */ jsx("div", { className: "u-eb-panel-isi", children: tab === "blok" ? blokPilih ? /* @__PURE__ */ jsx(PengaturanBlok, { b: blokPilih, ganti: (x) => r.set(ubahBlok(r.blok, x.id, () => x)) }) : /* @__PURE__ */ jsx("p", { className: "u-eb-redup", children: "Pilih satu blok di kanvas untuk melihat pengaturannya." }) : /* @__PURE__ */ jsxs("div", { className: "u-eb-dokumen", children: [
1946
+ panelDokumen,
1947
+ /* @__PURE__ */ jsxs("section", { children: [
1948
+ /* @__PURE__ */ jsxs("h3", { className: "u-eb-panel-judul", children: [
1949
+ /* @__PURE__ */ jsx(ListTree, { "aria-hidden": true }),
1950
+ "Daftar isi"
1951
+ ] }),
1952
+ isi.length ? /* @__PURE__ */ jsx("ol", { className: "u-eb-daftar-isi", children: isi.map((x, i) => /* @__PURE__ */ jsx("li", { "data-tingkat": x.tingkat, children: x.teks }, `${x.id}-${i}`)) }) : /* @__PURE__ */ jsx("p", { className: "u-eb-redup", children: "Tambahkan blok Judul (ketik ## di awal paragraf) untuk membagi tulisan." })
1953
+ ] }),
1954
+ /* @__PURE__ */ jsxs("section", { children: [
1955
+ /* @__PURE__ */ jsx("h3", { className: "u-eb-panel-judul", children: "Cek terbit" }),
1956
+ /* @__PURE__ */ jsx(DaftarCek, { cek })
1957
+ ] })
1958
+ ] }) })
1959
+ ] })
1960
+ ] }),
1961
+ /* @__PURE__ */ jsx(
1962
+ Dialog,
1963
+ {
1964
+ open: cekBuka,
1965
+ onOpenChange: setCekBuka,
1966
+ title: cek.some((c) => c.wajib && !c.ok) ? "Belum siap terbit" : "Siap terbit?",
1967
+ description: "Periksa sekali lagi sebelum tampil di semua situs terkait.",
1968
+ footer: /* @__PURE__ */ jsxs(Fragment, { children: [
1969
+ /* @__PURE__ */ jsx(Button, { variant: "outline", onClick: () => setCekBuka(false), children: "Kembali menyunting" }),
1970
+ aksi?.(nilai, cek)
1971
+ ] }),
1972
+ children: /* @__PURE__ */ jsx(DaftarCek, { cek })
1973
+ }
1974
+ )
1975
+ ] });
1976
+ }
1977
+ function DaftarCek({ cek }) {
1978
+ return /* @__PURE__ */ jsx("ul", { className: "u-eb-cek", children: cek.map((c) => /* @__PURE__ */ jsxs("li", { "data-ok": c.ok || void 0, "data-wajib": c.wajib && !c.ok || void 0, children: [
1979
+ c.ok ? /* @__PURE__ */ jsx(CheckCircle2, { "aria-hidden": true }) : c.wajib ? /* @__PURE__ */ jsx(AlertTriangle, { "aria-hidden": true }) : /* @__PURE__ */ jsx(Info, { "aria-hidden": true }),
1980
+ /* @__PURE__ */ jsx("span", { children: c.teks })
1981
+ ] }, c.teks)) });
1982
+ }
1983
+
1984
+ export { BISA_UBAH, DEF, DaftarCek, EditorBerita, EditorBlok, GalatBlok, Kanvas, MAKS_BLOK, MAKS_JSON, PengaturanBlok, Penyisip, RASIO, RENDER, TIPE_BLOK, TampilBlok, TeksSebaris, URUTAN_GRUP, baru, blokKeHtml, blokPola, cariBlok, cariSemua, cekTerbitBerita, daftarIsiBlok, embedVideo2 as embedVideo, hitungKata, htmlKeBlok, idBaru, jangkar, rapikan, rapikanHtml, salinBaru, saringSebaris, saringTipe, teksBlok, ubahBlok, ubahTipe, urlAman, urlPeta, useEditor, usePemilihMediaBawaan, useRiwayatBlok, validasiBlok, waktuBaca };
1985
+ //# sourceMappingURL=editor.js.map
1986
+ //# sourceMappingURL=editor.js.map