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.
- package/cli/index.mjs +53 -4
- package/dist/EditorBlok-CarZErBW.d.cts +155 -0
- package/dist/EditorBlok-CarZErBW.d.ts +155 -0
- package/dist/admisi-LKPO7LCR.js +11 -0
- package/dist/admisi-U6YYQGBB.cjs +20 -0
- package/dist/akademik-3DFVHKUD.cjs +20 -0
- package/dist/akademik-IXTTJMVD.js +11 -0
- package/dist/akses-AUPQD6YN.cjs +20 -0
- package/dist/akses-V5XIMBWT.js +11 -0
- package/dist/arsip-23P44PGP.cjs +20 -0
- package/dist/arsip-NZFZOTY7.js +11 -0
- package/dist/cbt-4N6COVIN.js +11 -0
- package/dist/cbt-GMQSR7TP.cjs +20 -0
- package/dist/chunk-3O5ELKBH.cjs +18 -0
- package/dist/chunk-3O5ELKBH.cjs.map +1 -0
- package/dist/chunk-BCHB7R6D.cjs +614 -0
- package/dist/chunk-BCHB7R6D.cjs.map +1 -0
- package/dist/chunk-BRARGLUX.js +462 -0
- package/dist/chunk-BRARGLUX.js.map +1 -0
- package/dist/chunk-CIVK5JDV.cjs +150 -0
- package/dist/chunk-CIVK5JDV.cjs.map +1 -0
- package/dist/{chunk-SJ4DJOMZ.js → chunk-DHQFANBE.js} +178 -1557
- package/dist/chunk-DHQFANBE.js.map +1 -0
- package/dist/chunk-JSUHAYQ4.js +15 -0
- package/dist/chunk-JSUHAYQ4.js.map +1 -0
- package/dist/chunk-LTADAXBH.cjs +510 -0
- package/dist/chunk-LTADAXBH.cjs.map +1 -0
- package/dist/chunk-NCRYPHOJ.cjs +2276 -0
- package/dist/chunk-NCRYPHOJ.cjs.map +1 -0
- package/dist/chunk-PC4G2C4M.js +1007 -0
- package/dist/chunk-PC4G2C4M.js.map +1 -0
- package/dist/chunk-PYMN25WD.js +2176 -0
- package/dist/chunk-PYMN25WD.js.map +1 -0
- package/dist/chunk-PYYLKWNZ.js +537 -0
- package/dist/chunk-PYYLKWNZ.js.map +1 -0
- package/dist/chunk-QHVQ6R55.cjs +1059 -0
- package/dist/chunk-QHVQ6R55.cjs.map +1 -0
- package/dist/chunk-TITKMSUS.cjs +2186 -0
- package/dist/chunk-TITKMSUS.cjs.map +1 -0
- package/dist/chunk-UA6AUXMY.js +122 -0
- package/dist/chunk-UA6AUXMY.js.map +1 -0
- package/dist/crm-C4XGSG6O.js +11 -0
- package/dist/crm-LTVCDNMK.cjs +20 -0
- package/dist/dasbor-OJLMSFTF.cjs +20 -0
- package/dist/dasbor-Y3UPFYFE.js +11 -0
- package/dist/editor.cjs +2050 -0
- package/dist/editor.cjs.map +1 -0
- package/dist/editor.d.cts +202 -0
- package/dist/editor.d.ts +202 -0
- package/dist/editor.js +1986 -0
- package/dist/editor.js.map +1 -0
- package/dist/edom-3GZUUB7H.cjs +20 -0
- package/dist/edom-K4Y2NV4K.js +11 -0
- package/dist/fakultas-DJRUVJBV.js +11 -0
- package/dist/fakultas-VVAQOPUX.cjs +20 -0
- package/dist/filter-D54KALbB.d.cts +436 -0
- package/dist/filter-D54KALbB.d.ts +436 -0
- package/dist/helpdesk-LV65LM5V.js +11 -0
- package/dist/helpdesk-S7GAHYXG.cjs +20 -0
- package/dist/humas-7BMMJ3WF.js +11 -0
- package/dist/humas-H56JFUW6.cjs +20 -0
- package/dist/ikon.cjs +125 -0
- package/dist/ikon.cjs.map +1 -0
- package/dist/ikon.d.cts +140 -0
- package/dist/ikon.d.ts +140 -0
- package/dist/ikon.js +6 -0
- package/dist/ikon.js.map +1 -0
- package/dist/iku-CJG75NAT.cjs +20 -0
- package/dist/iku-XFGUJ6CX.js +11 -0
- package/dist/index.cjs +601 -313
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +192 -2
- package/dist/index.d.ts +192 -2
- package/dist/index.js +128 -4
- package/dist/index.js.map +1 -1
- package/dist/induk-BGTGKRLL.js +11 -0
- package/dist/induk-DLYDMZAM.cjs +20 -0
- package/dist/integrasi-4VXNGA3V.cjs +20 -0
- package/dist/integrasi-IP3WWDO7.js +11 -0
- package/dist/kalender-NZH7F2LO.js +11 -0
- package/dist/kalender-SD7EUASC.cjs +20 -0
- package/dist/karier-BDPZONV6.cjs +20 -0
- package/dist/karier-VHUJKKD6.js +11 -0
- package/dist/katalog.cjs +1806 -0
- package/dist/katalog.cjs.map +1 -0
- package/dist/katalog.d.cts +650 -0
- package/dist/katalog.d.ts +650 -0
- package/dist/katalog.js +1721 -0
- package/dist/katalog.js.map +1 -0
- package/dist/kelulusan-3QCPPC3D.js +11 -0
- package/dist/kelulusan-X7DYJN6T.cjs +20 -0
- package/dist/kemahasiswaan-JNCMH3HR.js +11 -0
- package/dist/kemahasiswaan-MQYXEVKE.cjs +20 -0
- package/dist/kerjasama-KYHEBSLX.cjs +20 -0
- package/dist/kerjasama-QSZ5X4OB.js +11 -0
- package/dist/keu-6H5WH6A4.js +11 -0
- package/dist/keu-MIJRVMGW.cjs +20 -0
- package/dist/kurikulum-SRO7TJYI.cjs +20 -0
- package/dist/kurikulum-XT7PZJOK.js +11 -0
- package/dist/layanan-H25JKJKC.js +11 -0
- package/dist/layanan-XR75P7YX.cjs +20 -0
- package/dist/lms-2ZCH273D.cjs +20 -0
- package/dist/lms-MFXFO2AZ.js +11 -0
- package/dist/lppm-B7ECUONV.js +11 -0
- package/dist/lppm-QEQKZXCY.cjs +20 -0
- package/dist/master-GKTTAKLF.cjs +20 -0
- package/dist/master-ZG4SPPDU.js +11 -0
- package/dist/mbkm-737Q4WFQ.js +11 -0
- package/dist/mbkm-GMNFIFDS.cjs +20 -0
- package/dist/notifikasi-FMA26M4I.js +11 -0
- package/dist/notifikasi-QDCYIX7G.cjs +20 -0
- package/dist/pddikti-RJVYY2J4.cjs +20 -0
- package/dist/pddikti-VF2PXDKA.js +11 -0
- package/dist/{content-DaJPx5LX.d.cts → pemeliharaan-D5S-1lqW.d.ts} +38 -434
- package/dist/{content-DaJPx5LX.d.ts → pemeliharaan-Dr0HSxvZ.d.cts} +38 -434
- package/dist/perpustakaan-5RL33XG2.js +11 -0
- package/dist/perpustakaan-JXZW43MJ.cjs +20 -0
- package/dist/pilih-BEes_D3n.d.cts +205 -0
- package/dist/pilih-CEKqXMUS.d.ts +205 -0
- package/dist/pmb-EGTWW2ZH.cjs +20 -0
- package/dist/pmb-G7EAFJ3R.js +11 -0
- package/dist/portal-5LCG6IP3.cjs +20 -0
- package/dist/portal-NYR3OIU4.js +11 -0
- package/dist/portal-api-BJLO6AGI.js +11 -0
- package/dist/portal-api-Q6B3X6ZV.cjs +20 -0
- package/dist/profil-FA2WXZR5.js +11 -0
- package/dist/profil-J4DRC6LS.cjs +20 -0
- package/dist/referensi-HNYOJGNX.js +11 -0
- package/dist/referensi-VOT5BRCL.cjs +20 -0
- package/dist/registry.json +996 -4
- package/dist/repositori-4GHBDDQA.js +11 -0
- package/dist/repositori-JRDIIPDJ.cjs +20 -0
- package/dist/rpl-4RGI6RNL.js +11 -0
- package/dist/rpl-NBVCZHQF.cjs +20 -0
- package/dist/sarpras-TAF4M2NQ.js +11 -0
- package/dist/sarpras-TXNUAX4Y.cjs +20 -0
- package/dist/scss/components/_animasi.scss +280 -0
- package/dist/scss/components/_editor.scss +1093 -0
- package/dist/scss/components/_ikon.scss +339 -0
- package/dist/scss/components/_katalog.scss +662 -0
- package/dist/scss/components/_konten-blok.scss +413 -0
- package/dist/scss/components/_pilih-berkas.scss +156 -0
- package/dist/scss/components/_platform.scss +364 -0
- package/dist/scss/index.scss +7 -0
- package/dist/sdm-5YKAAV3T.js +11 -0
- package/dist/sdm-IN64PE3T.cjs +20 -0
- package/dist/siakad.cjs +1487 -3078
- package/dist/siakad.cjs.map +1 -1
- package/dist/siakad.d.cts +84 -196
- package/dist/siakad.d.ts +84 -196
- package/dist/siakad.js +473 -2307
- package/dist/siakad.js.map +1 -1
- package/dist/spmi-AXZ5B3EJ.cjs +20 -0
- package/dist/spmi-LMUM2XER.js +11 -0
- package/dist/tracer-UBUAIJEK.js +11 -0
- package/dist/tracer-WWVIA55Q.cjs +20 -0
- package/dist/ui-unipo.css +3505 -0
- package/dist/ui-unipo.min.css +1 -1
- package/package.json +35 -3
- package/src/components/animasi.tsx +186 -0
- package/src/components/modal.tsx +113 -0
- package/src/components/overlays.tsx +6 -1
- package/src/components/pemeliharaan.tsx +152 -0
- package/src/components/platform.tsx +94 -0
- package/src/editor/EditorBerita.tsx +297 -0
- package/src/editor/EditorBlok.tsx +367 -0
- package/src/editor/Kanvas.tsx +322 -0
- package/src/editor/Penyisip.tsx +185 -0
- package/src/editor/TeksSebaris.tsx +190 -0
- package/src/editor/blok/Media.tsx +132 -0
- package/src/editor/blok/Tata.tsx +115 -0
- package/src/editor/blok/Teks.tsx +182 -0
- package/src/editor/blok/index.tsx +212 -0
- package/src/editor/blok/props.ts +24 -0
- package/src/editor/index.ts +10 -0
- package/src/editor/konteks.tsx +58 -0
- package/src/editor/render.ts +232 -0
- package/src/editor/tipe.ts +225 -0
- package/src/ikon/ilustrasi.tsx +283 -0
- package/src/ikon/index.ts +7 -0
- package/src/ikon/kotak.tsx +30 -0
- package/src/ikon/unipo.tsx +326 -0
- package/src/index.ts +8 -0
- package/src/katalog/aturan.ts +515 -0
- package/src/katalog/data/id.ts +749 -0
- package/src/katalog/data/indeks.json +1 -0
- package/src/katalog/data/muat.ts +47 -0
- package/src/katalog/ikon.tsx +11 -0
- package/src/katalog/index.ts +13 -0
- package/src/katalog/isian.tsx +408 -0
- package/src/katalog/katalog.tsx +138 -0
- package/src/katalog/kelola.tsx +690 -0
- package/src/katalog/modul.tsx +336 -0
- package/src/katalog/tampil.tsx +147 -0
- package/src/katalog/tipe.ts +141 -0
- package/src/katalog/wizard.tsx +155 -0
- package/src/lib/platform.ts +91 -0
- package/src/siakad/index.ts +3 -0
- package/src/siakad/media-editor.ts +67 -0
- package/src/siakad/pemeliharaan.tsx +118 -0
- package/src/siakad/pilih-berkas.tsx +292 -0
- package/src/siakad/provider.tsx +2 -0
- package/dist/chunk-DEF5CA7C.cjs +0 -3648
- package/dist/chunk-DEF5CA7C.cjs.map +0 -1
- package/dist/chunk-SJ4DJOMZ.js.map +0 -1
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
import { useRef, useState, type DragEvent, type KeyboardEvent } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
Bold, ChevronDown, ChevronUp, Code, Copy, GripVertical, Highlighter, Italic, Link2, MoreVertical, Plus, Trash2, Unlink,
|
|
4
|
+
} from 'lucide-react';
|
|
5
|
+
import { cn } from '../lib/cn';
|
|
6
|
+
import { Menu } from '../components/overlays';
|
|
7
|
+
import { BISA_UBAH, RENDER, ubahTipe, type OpsBlok } from './blok';
|
|
8
|
+
import { useEditor } from './konteks';
|
|
9
|
+
import { Penyisip } from './Penyisip';
|
|
10
|
+
import { baru, DEF, salinBaru, type Blok } from './tipe';
|
|
11
|
+
|
|
12
|
+
const polos = (h: string) => h.replace(/<[^>]+>/g, '').replace(/ /g, ' ').replace(/&[a-z]+;/g, '_');
|
|
13
|
+
|
|
14
|
+
/** Id elemen teks yang difokus untuk blok (butir daftar punya id sendiri). */
|
|
15
|
+
export function idFokus(b: Blok, akhir: boolean): string {
|
|
16
|
+
if (b.tipe === 'daftar') return `${b.id}~${akhir ? Math.max(0, (b.data.item?.length ?? 1) - 1) : 0}`;
|
|
17
|
+
return b.id;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** Elemen contentEditable yang memuat seleksi saat ini. */
|
|
21
|
+
function editableAktif(): HTMLElement | null {
|
|
22
|
+
const n = window.getSelection()?.anchorNode;
|
|
23
|
+
const el = n ? (n.nodeType === 1 ? (n as HTMLElement) : n.parentElement) : null;
|
|
24
|
+
return el?.closest('[contenteditable="true"]') ?? null;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function bungkusMark() {
|
|
28
|
+
const sel = window.getSelection();
|
|
29
|
+
const akar = editableAktif();
|
|
30
|
+
if (!sel || sel.rangeCount === 0 || sel.isCollapsed || !akar) return;
|
|
31
|
+
const r = sel.getRangeAt(0);
|
|
32
|
+
const m = document.createElement('mark');
|
|
33
|
+
m.appendChild(r.extractContents());
|
|
34
|
+
r.insertNode(m);
|
|
35
|
+
akar.dispatchEvent(new Event('input', { bubbles: true }));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function bungkusKode() {
|
|
39
|
+
const sel = window.getSelection();
|
|
40
|
+
const akar = editableAktif();
|
|
41
|
+
if (!sel || sel.rangeCount === 0 || sel.isCollapsed || !akar) return;
|
|
42
|
+
const r = sel.getRangeAt(0);
|
|
43
|
+
const c = document.createElement('code');
|
|
44
|
+
c.textContent = r.toString();
|
|
45
|
+
r.deleteContents();
|
|
46
|
+
r.insertNode(c);
|
|
47
|
+
akar.dispatchEvent(new Event('input', { bubbles: true }));
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Tombol format teks sebaris + isian tautan. Tombol memakai onMouseDown agar seleksi tidak hilang. */
|
|
51
|
+
function FormatTeks() {
|
|
52
|
+
const [tautan, setTautan] = useState<{ r: Range; url: string } | null>(null);
|
|
53
|
+
const tombol = (label: string, Ikon: typeof Bold, aksi: () => void) => (
|
|
54
|
+
<button key={label} type="button" title={label} aria-label={label} onMouseDown={(e) => { e.preventDefault(); aksi(); }}
|
|
55
|
+
className="u-eb-tb"><Ikon aria-hidden /></button>
|
|
56
|
+
);
|
|
57
|
+
return (
|
|
58
|
+
<>
|
|
59
|
+
{tombol('Tebal (Ctrl+B)', Bold, () => document.execCommand('bold'))}
|
|
60
|
+
{tombol('Miring (Ctrl+I)', Italic, () => document.execCommand('italic'))}
|
|
61
|
+
{tombol('Tautan (Ctrl+K)', Link2, () => {
|
|
62
|
+
const sel = window.getSelection();
|
|
63
|
+
if (sel && sel.rangeCount && editableAktif()) setTautan({ r: sel.getRangeAt(0).cloneRange(), url: 'https://' });
|
|
64
|
+
})}
|
|
65
|
+
{tombol('Hapus tautan', Unlink, () => document.execCommand('unlink'))}
|
|
66
|
+
{tombol('Sorot', Highlighter, bungkusMark)}
|
|
67
|
+
{tombol('Kode sebaris', Code, bungkusKode)}
|
|
68
|
+
{tautan && (
|
|
69
|
+
<form className="u-eb-tautan-form"
|
|
70
|
+
onSubmit={(e) => {
|
|
71
|
+
e.preventDefault();
|
|
72
|
+
const sel = window.getSelection();
|
|
73
|
+
sel?.removeAllRanges();
|
|
74
|
+
sel?.addRange(tautan.r);
|
|
75
|
+
if (tautan.url.trim() && tautan.url !== 'https://') {
|
|
76
|
+
if (tautan.r.collapsed) document.execCommand('insertHTML', false, `<a href="${tautan.url.replace(/"/g, '%22')}">${tautan.url.replace(/</g, '<')}</a>`);
|
|
77
|
+
else document.execCommand('createLink', false, tautan.url.trim());
|
|
78
|
+
}
|
|
79
|
+
setTautan(null);
|
|
80
|
+
}}>
|
|
81
|
+
<input autoFocus value={tautan.url} onChange={(e) => setTautan({ ...tautan, url: e.target.value })} onKeyDown={(e) => e.key === 'Escape' && setTautan(null)}
|
|
82
|
+
className="u-input" data-size="sm" aria-label="Alamat tautan" />
|
|
83
|
+
<button type="submit" className="u-btn" data-variant="primary" data-size="sm">Pasang</button>
|
|
84
|
+
</form>
|
|
85
|
+
)}
|
|
86
|
+
</>
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
interface PropsBilah {
|
|
91
|
+
b: Blok;
|
|
92
|
+
i: number;
|
|
93
|
+
jumlah: number;
|
|
94
|
+
pindah: (arah: -1 | 1) => void;
|
|
95
|
+
ganti: (b: Blok) => void;
|
|
96
|
+
duplikat: () => void;
|
|
97
|
+
sisipSebelum: () => void;
|
|
98
|
+
sisipSesudah: () => void;
|
|
99
|
+
hapus: () => void;
|
|
100
|
+
mulaiSeret: (e: DragEvent) => void;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** Bilah alat blok terpilih: tipe, seret, naik/turun, format teks, menu lainnya. */
|
|
104
|
+
function BilahBlok({ b, i, jumlah, pindah, ganti, duplikat, sisipSebelum, sisipSesudah, hapus, mulaiSeret }: PropsBilah) {
|
|
105
|
+
const D = DEF[b.tipe];
|
|
106
|
+
const I = D.ikon;
|
|
107
|
+
const teks = D.teks || ['daftar', 'sorotan', 'tabel', 'akordion'].includes(b.tipe);
|
|
108
|
+
const bisaUbah = BISA_UBAH.includes(b.tipe);
|
|
109
|
+
const kotak = 'u-eb-bilah-kotak';
|
|
110
|
+
const tb = 'u-eb-tb';
|
|
111
|
+
return (
|
|
112
|
+
<div className="u-eb-bilah" contentEditable={false} onMouseDown={(e) => e.stopPropagation()}>
|
|
113
|
+
<div className={kotak}>
|
|
114
|
+
{bisaUbah ? (
|
|
115
|
+
<Menu align="start" trigger={<button type="button" title={`${D.label}: ubah jenis blok`} aria-label={`${D.label}: ubah jenis blok`} className={tb}><I aria-hidden /></button>}
|
|
116
|
+
items={BISA_UBAH.filter((t) => t !== b.tipe).map((t) => { const X = DEF[t].ikon; return { label: DEF[t].label, icon: <X />, onSelect: () => ganti(ubahTipe(b, t)) }; })} />
|
|
117
|
+
) : <span className={tb} title={D.label}><I aria-hidden /></span>}
|
|
118
|
+
<span draggable onDragStart={mulaiSeret} title="Seret untuk memindah" className={cn(tb, 'u-eb-seret')}><GripVertical aria-hidden /></span>
|
|
119
|
+
<span className="u-eb-naik-turun">
|
|
120
|
+
<button type="button" disabled={i === 0} onClick={() => pindah(-1)} aria-label="Naikkan"><ChevronUp aria-hidden /></button>
|
|
121
|
+
<button type="button" disabled={i === jumlah - 1} onClick={() => pindah(1)} aria-label="Turunkan"><ChevronDown aria-hidden /></button>
|
|
122
|
+
</span>
|
|
123
|
+
</div>
|
|
124
|
+
{teks && <div className={cn(kotak, 'u-eb-format')}><FormatTeks /></div>}
|
|
125
|
+
<div className={kotak}>
|
|
126
|
+
<Menu trigger={<button type="button" className={tb} aria-label="Lainnya"><MoreVertical aria-hidden /></button>} items={[
|
|
127
|
+
{ label: 'Duplikat', icon: <Copy />, onSelect: duplikat },
|
|
128
|
+
{ label: 'Sisip blok sebelum', icon: <Plus />, onSelect: sisipSebelum },
|
|
129
|
+
{ label: 'Sisip blok sesudah', icon: <Plus />, onSelect: sisipSesudah },
|
|
130
|
+
{ type: 'separator' },
|
|
131
|
+
{ label: 'Hapus blok', icon: <Trash2 />, onSelect: hapus, destructive: true },
|
|
132
|
+
]} />
|
|
133
|
+
</div>
|
|
134
|
+
</div>
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** Daftar blok yang bisa disunting. Dipakai untuk isi utama dan untuk tiap kolom blok Kolom. */
|
|
139
|
+
export function Kanvas({ daftar, ganti, dalamKolom }: { daftar: Blok[]; ganti: (d: Blok[]) => void; dalamKolom?: boolean }) {
|
|
140
|
+
const { pilih, setPilih, setFokus, baca } = useEditor();
|
|
141
|
+
const [penyisip, setPenyisip] = useState<{ i: number; el: HTMLElement } | null>(null);
|
|
142
|
+
const [seret, setSeret] = useState<{ dari: number; ke: number } | null>(null);
|
|
143
|
+
const akhirRef = useRef<HTMLButtonElement>(null);
|
|
144
|
+
|
|
145
|
+
const fokuskan = (b: Blok, akhir: boolean) => {
|
|
146
|
+
setPilih(b.id);
|
|
147
|
+
if (DEF[b.tipe].teks || b.tipe === 'daftar') setFokus({ id: idFokus(b, akhir), di: akhir ? 'akhir' : 'awal' });
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
const sisip = (i: number, bs: Blok[], fokusKe = 0) => {
|
|
151
|
+
const n = [...daftar];
|
|
152
|
+
n.splice(i, 0, ...bs);
|
|
153
|
+
ganti(n);
|
|
154
|
+
if (bs[fokusKe]) fokuskan(bs[fokusKe], true);
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
const hapus = (i: number) => {
|
|
158
|
+
const n = daftar.filter((_, j) => j !== i);
|
|
159
|
+
ganti(n.length || dalamKolom ? n : [baru('paragraf')]);
|
|
160
|
+
const sebelum = n[i - 1] ?? n[0];
|
|
161
|
+
if (sebelum) fokuskan(sebelum, true);
|
|
162
|
+
else setPilih(null);
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
const pindah = (i: number, a: -1 | 1) => {
|
|
166
|
+
const j = i + a;
|
|
167
|
+
if (j < 0 || j >= daftar.length) return;
|
|
168
|
+
const n = [...daftar];
|
|
169
|
+
[n[i], n[j]] = [n[j], n[i]];
|
|
170
|
+
ganti(n);
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
const opsUntuk = (i: number): OpsBlok => ({
|
|
174
|
+
pecah: (s, d) => {
|
|
175
|
+
const b = daftar[i];
|
|
176
|
+
const p = baru('paragraf', { teks: d });
|
|
177
|
+
const n = [...daftar];
|
|
178
|
+
n.splice(i, 1, { ...b, data: { ...b.data, teks: s } }, p);
|
|
179
|
+
ganti(n);
|
|
180
|
+
setPilih(p.id);
|
|
181
|
+
setFokus({ id: p.id, di: 'awal' });
|
|
182
|
+
},
|
|
183
|
+
gabungAtas: (html) => {
|
|
184
|
+
const b = daftar[i];
|
|
185
|
+
const prev = daftar[i - 1];
|
|
186
|
+
if (!prev) {
|
|
187
|
+
if (b.tipe !== 'paragraf' && DEF[b.tipe].teks) ganti(daftar.map((x, j) => (j === i ? ubahTipe(b, 'paragraf') : x)));
|
|
188
|
+
else if (!html && daftar.length > 1) hapus(i);
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
const n = daftar.filter((_, j) => j !== i);
|
|
192
|
+
if (DEF[prev.tipe].teks && typeof prev.data.teks === 'string') {
|
|
193
|
+
const pos = polos(prev.data.teks).length;
|
|
194
|
+
n[i - 1] = { ...prev, data: { ...prev.data, teks: prev.data.teks + html } };
|
|
195
|
+
ganti(n);
|
|
196
|
+
setPilih(prev.id);
|
|
197
|
+
setFokus({ id: prev.id, di: pos });
|
|
198
|
+
} else if (prev.tipe === 'daftar') {
|
|
199
|
+
const item: string[] = [...(prev.data.item ?? [''])];
|
|
200
|
+
const pos = polos(item[item.length - 1] ?? '').length;
|
|
201
|
+
item[item.length - 1] = (item[item.length - 1] ?? '') + html;
|
|
202
|
+
n[i - 1] = { ...prev, data: { ...prev.data, item } };
|
|
203
|
+
ganti(n);
|
|
204
|
+
setPilih(prev.id);
|
|
205
|
+
setFokus({ id: `${prev.id}~${item.length - 1}`, di: pos });
|
|
206
|
+
} else if (!html) {
|
|
207
|
+
ganti(n);
|
|
208
|
+
setPilih(prev.id);
|
|
209
|
+
} else setPilih(prev.id);
|
|
210
|
+
},
|
|
211
|
+
panah: (a) => {
|
|
212
|
+
const t = daftar[i + a];
|
|
213
|
+
if (t) fokuskan(t, a < 0);
|
|
214
|
+
},
|
|
215
|
+
ubahJadi: (bs, fokusKe = 0) => {
|
|
216
|
+
const n = [...daftar];
|
|
217
|
+
n.splice(i, 1, ...bs);
|
|
218
|
+
ganti(n);
|
|
219
|
+
if (bs[fokusKe]) fokuskan(bs[fokusKe], true);
|
|
220
|
+
},
|
|
221
|
+
sisipSesudah: (b) => sisip(i + 1, [b]),
|
|
222
|
+
hapus: () => hapus(i),
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
const lepas = (e: DragEvent) => {
|
|
226
|
+
if (!seret) return;
|
|
227
|
+
e.preventDefault();
|
|
228
|
+
const { dari, ke } = seret;
|
|
229
|
+
setSeret(null);
|
|
230
|
+
if (ke === dari || ke === dari + 1) return;
|
|
231
|
+
const n = [...daftar];
|
|
232
|
+
const [b] = n.splice(dari, 1);
|
|
233
|
+
n.splice(ke > dari ? ke - 1 : ke, 0, b);
|
|
234
|
+
ganti(n);
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
return (
|
|
238
|
+
<div className={cn('u-eb-kanvas', dalamKolom && 'u-eb-kanvas-kolom')} onDragOver={(e) => seret && e.preventDefault()} onDrop={lepas}>
|
|
239
|
+
{daftar.map((b, i) => {
|
|
240
|
+
const R = RENDER[b.tipe];
|
|
241
|
+
const terpilih = pilih === b.id && !baca;
|
|
242
|
+
const garisSeret = seret && seret.ke === i && seret.dari !== i && seret.dari !== i - 1;
|
|
243
|
+
return (
|
|
244
|
+
<div key={b.id} data-blok={b.id} tabIndex={-1}
|
|
245
|
+
className="u-eb-blok"
|
|
246
|
+
data-terpilih={terpilih || undefined}
|
|
247
|
+
data-baca={baca || undefined}
|
|
248
|
+
data-diseret={seret?.dari === i || undefined}
|
|
249
|
+
onMouseDown={(e) => { e.stopPropagation(); if (pilih !== b.id) setPilih(b.id); }}
|
|
250
|
+
onFocus={(e) => { e.stopPropagation(); if (pilih !== b.id) setPilih(b.id); }}
|
|
251
|
+
onKeyDown={(e: KeyboardEvent<HTMLDivElement>) => {
|
|
252
|
+
if (e.target !== e.currentTarget) return;
|
|
253
|
+
if (e.key === 'Backspace' || e.key === 'Delete') { e.preventDefault(); hapus(i); }
|
|
254
|
+
if (e.key === 'Enter') { e.preventDefault(); sisip(i + 1, [baru('paragraf')]); }
|
|
255
|
+
}}
|
|
256
|
+
onDragOver={(e) => {
|
|
257
|
+
if (!seret) return;
|
|
258
|
+
e.preventDefault();
|
|
259
|
+
e.stopPropagation();
|
|
260
|
+
const r = e.currentTarget.getBoundingClientRect();
|
|
261
|
+
const ke = e.clientY < r.top + r.height / 2 ? i : i + 1;
|
|
262
|
+
if (ke !== seret.ke) setSeret({ ...seret, ke });
|
|
263
|
+
}}
|
|
264
|
+
onDragEnd={() => setSeret(null)}>
|
|
265
|
+
{garisSeret && <div className="u-eb-garis-seret" data-posisi="atas" />}
|
|
266
|
+
{i === daftar.length - 1 && seret && seret.ke === daftar.length && seret.dari !== i && <div className="u-eb-garis-seret" data-posisi="bawah" />}
|
|
267
|
+
{terpilih && (
|
|
268
|
+
<BilahBlok b={b} i={i} jumlah={daftar.length} pindah={(a) => pindah(i, a)}
|
|
269
|
+
ganti={(x) => { ganti(daftar.map((y, j) => (j === i ? x : y))); fokuskan(x, true); }}
|
|
270
|
+
duplikat={() => sisip(i + 1, [salinBaru(b)])}
|
|
271
|
+
sisipSebelum={() => sisip(i, [baru('paragraf')])}
|
|
272
|
+
sisipSesudah={() => sisip(i + 1, [baru('paragraf')])}
|
|
273
|
+
hapus={() => hapus(i)}
|
|
274
|
+
mulaiSeret={(e) => {
|
|
275
|
+
e.dataTransfer.effectAllowed = 'move';
|
|
276
|
+
e.dataTransfer.setData('text/plain', b.id);
|
|
277
|
+
const el = (e.currentTarget as HTMLElement).closest('[data-blok]');
|
|
278
|
+
if (el) e.dataTransfer.setDragImage(el, 20, 20);
|
|
279
|
+
setSeret({ dari: i, ke: i });
|
|
280
|
+
}} />
|
|
281
|
+
)}
|
|
282
|
+
<R b={b} terpilih={terpilih} ops={opsUntuk(i)}
|
|
283
|
+
ubah={(d) => ganti(daftar.map((x, j) => (j === i ? { ...x, data: { ...x.data, ...d } } : x)))}
|
|
284
|
+
ganti={(x) => ganti(daftar.map((y, j) => (j === i ? x : y)))} />
|
|
285
|
+
{!baca && (
|
|
286
|
+
<button type="button" aria-label="Sisipkan blok di sini" title="Sisipkan blok"
|
|
287
|
+
onMouseDown={(e) => e.stopPropagation()}
|
|
288
|
+
onClick={(e) => setPenyisip({ i: i + 1, el: e.currentTarget })}
|
|
289
|
+
className="u-eb-sisip-antara">
|
|
290
|
+
<Plus aria-hidden />
|
|
291
|
+
</button>
|
|
292
|
+
)}
|
|
293
|
+
</div>
|
|
294
|
+
);
|
|
295
|
+
})}
|
|
296
|
+
{!baca && (
|
|
297
|
+
<button ref={akhirRef} type="button" onClick={(e) => {
|
|
298
|
+
const akhir = daftar[daftar.length - 1];
|
|
299
|
+
if (!dalamKolom && akhir?.tipe === 'paragraf' && !akhir.data.teks) setPenyisip({ i: daftar.length, el: e.currentTarget });
|
|
300
|
+
else sisip(daftar.length, [baru('paragraf')]);
|
|
301
|
+
}}
|
|
302
|
+
className="u-eb-tambah-akhir" data-kolom={dalamKolom || undefined}>
|
|
303
|
+
<Plus aria-hidden />{dalamKolom ? 'Blok' : 'Tambah blok (atau ketik / di paragraf kosong)'}
|
|
304
|
+
</button>
|
|
305
|
+
)}
|
|
306
|
+
{penyisip && (
|
|
307
|
+
<Penyisip jangkar={penyisip.el} tanpaKolom={dalamKolom} tutup={() => setPenyisip(null)} pilih={(bs) => {
|
|
308
|
+
const i = penyisip.i;
|
|
309
|
+
setPenyisip(null);
|
|
310
|
+
const akhir = daftar[i - 1];
|
|
311
|
+
// Ganti paragraf kosong di posisi itu daripada menyisakan baris kosong.
|
|
312
|
+
if (akhir && akhir.tipe === 'paragraf' && !akhir.data.teks && i === daftar.length) {
|
|
313
|
+
const n = [...daftar];
|
|
314
|
+
n.splice(i - 1, 1, ...bs);
|
|
315
|
+
ganti(n);
|
|
316
|
+
fokuskan(bs[0], true);
|
|
317
|
+
} else sisip(i, bs);
|
|
318
|
+
}} />
|
|
319
|
+
)}
|
|
320
|
+
</div>
|
|
321
|
+
);
|
|
322
|
+
}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { createPortal } from 'react-dom';
|
|
3
|
+
import { LayoutTemplate, Search } from 'lucide-react';
|
|
4
|
+
import { cn } from '../lib/cn';
|
|
5
|
+
import { useEditor, type PolaBlok } from './konteks';
|
|
6
|
+
import { baru, DEF, rapikan, salinBaru, URUTAN_GRUP, type Blok, type TipeBlok } from './tipe';
|
|
7
|
+
|
|
8
|
+
const SEMUA = Object.keys(DEF) as TipeBlok[];
|
|
9
|
+
|
|
10
|
+
/** Saring tipe blok dari kata pencarian (label, kata kunci, deskripsi). */
|
|
11
|
+
export function saringTipe(q: string, tipe: TipeBlok[] = SEMUA): TipeBlok[] {
|
|
12
|
+
const k = q.trim().toLowerCase();
|
|
13
|
+
if (!k) return tipe;
|
|
14
|
+
return tipe
|
|
15
|
+
.map((t) => {
|
|
16
|
+
const d = DEF[t];
|
|
17
|
+
const label = d.label.toLowerCase();
|
|
18
|
+
const skor = label.startsWith(k) ? 3 : label.includes(k) ? 2 : `${d.kunci ?? ''} ${d.deskripsi}`.toLowerCase().includes(k) ? 1 : 0;
|
|
19
|
+
return { t, skor };
|
|
20
|
+
})
|
|
21
|
+
.filter((x) => x.skor > 0)
|
|
22
|
+
.sort((a, b) => b.skor - a.skor)
|
|
23
|
+
.map((x) => x.t);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Isi pola siap disisipkan (id baru). */
|
|
27
|
+
export const blokPola = (p: PolaBlok): Blok[] => rapikan(p.blok).map(salinBaru);
|
|
28
|
+
|
|
29
|
+
/** Popover penyisip: tab Blok (cari + kisi per grup) dan tab Pola. Posisi di bawah elemen jangkar. */
|
|
30
|
+
export function Penyisip({ jangkar, pilih, tutup, tanpaKolom }: { jangkar: HTMLElement | null; pilih: (b: Blok[]) => void; tutup: () => void; tanpaKolom?: boolean }) {
|
|
31
|
+
const { pola } = useEditor();
|
|
32
|
+
const [tab, setTab] = React.useState<'blok' | 'pola'>('blok');
|
|
33
|
+
const [q, setQ] = React.useState('');
|
|
34
|
+
const ref = React.useRef<HTMLDivElement>(null);
|
|
35
|
+
const [pos, setPos] = React.useState<{ top: number; left: number }>({ top: 0, left: 0 });
|
|
36
|
+
|
|
37
|
+
React.useLayoutEffect(() => {
|
|
38
|
+
const r = jangkar?.getBoundingClientRect();
|
|
39
|
+
if (!r) return;
|
|
40
|
+
const lebar = Math.min(352, window.innerWidth - 16);
|
|
41
|
+
const left = Math.max(8, Math.min(r.left + r.width / 2 - lebar / 2, window.innerWidth - lebar - 8));
|
|
42
|
+
const bawah = window.innerHeight - r.bottom;
|
|
43
|
+
setPos({ top: bawah > 380 ? r.bottom + 6 : Math.max(8, r.top - 386), left });
|
|
44
|
+
}, [jangkar]);
|
|
45
|
+
|
|
46
|
+
React.useEffect(() => {
|
|
47
|
+
const klik = (e: MouseEvent) => {
|
|
48
|
+
if (ref.current && !ref.current.contains(e.target as Node) && !jangkar?.contains(e.target as Node)) tutup();
|
|
49
|
+
};
|
|
50
|
+
const esc = (e: KeyboardEvent) => e.key === 'Escape' && tutup();
|
|
51
|
+
document.addEventListener('mousedown', klik);
|
|
52
|
+
document.addEventListener('keydown', esc);
|
|
53
|
+
return () => {
|
|
54
|
+
document.removeEventListener('mousedown', klik);
|
|
55
|
+
document.removeEventListener('keydown', esc);
|
|
56
|
+
};
|
|
57
|
+
}, [jangkar, tutup]);
|
|
58
|
+
|
|
59
|
+
const tipe = saringTipe(q, tanpaKolom ? SEMUA.filter((t) => t !== 'kolom') : SEMUA);
|
|
60
|
+
const grupPola = React.useMemo(() => {
|
|
61
|
+
const m = new Map<string, PolaBlok[]>();
|
|
62
|
+
(pola ?? []).filter((p) => !q || `${p.nama} ${p.kategori}`.toLowerCase().includes(q.toLowerCase())).forEach((p) => m.set(p.kategori, [...(m.get(p.kategori) ?? []), p]));
|
|
63
|
+
return [...m.entries()];
|
|
64
|
+
}, [pola, q]);
|
|
65
|
+
|
|
66
|
+
return createPortal(
|
|
67
|
+
<div ref={ref} style={{ top: pos.top, left: pos.left }} className="u-eb-penyisip" role="dialog" aria-label="Sisipkan blok">
|
|
68
|
+
<div className="u-eb-penyisip-cari">
|
|
69
|
+
<Search aria-hidden />
|
|
70
|
+
<input
|
|
71
|
+
autoFocus
|
|
72
|
+
value={q}
|
|
73
|
+
onChange={(e) => setQ(e.target.value)}
|
|
74
|
+
placeholder={pola ? 'Cari blok atau pola' : 'Cari blok'}
|
|
75
|
+
aria-label="Cari blok"
|
|
76
|
+
onKeyDown={(e) => {
|
|
77
|
+
if (e.key === 'Enter' && tab === 'blok' && tipe[0]) {
|
|
78
|
+
e.preventDefault();
|
|
79
|
+
pilih([baru(tipe[0])]);
|
|
80
|
+
}
|
|
81
|
+
}}
|
|
82
|
+
/>
|
|
83
|
+
</div>
|
|
84
|
+
{pola && (
|
|
85
|
+
<div className="u-eb-penyisip-tab" role="tablist">
|
|
86
|
+
<button type="button" role="tab" aria-selected={tab === 'blok'} onClick={() => setTab('blok')}>
|
|
87
|
+
Blok
|
|
88
|
+
</button>
|
|
89
|
+
<button type="button" role="tab" aria-selected={tab === 'pola'} onClick={() => setTab('pola')}>
|
|
90
|
+
<LayoutTemplate aria-hidden />
|
|
91
|
+
Pola <span className="u-eb-jumlah">{pola.length}</span>
|
|
92
|
+
</button>
|
|
93
|
+
</div>
|
|
94
|
+
)}
|
|
95
|
+
<div className="u-eb-penyisip-isi">
|
|
96
|
+
{tab === 'blok' &&
|
|
97
|
+
(tipe.length === 0 ? (
|
|
98
|
+
<p className="u-eb-kosong">Tidak ada blok “{q}”.</p>
|
|
99
|
+
) : q ? (
|
|
100
|
+
<div className="u-eb-kisi-tipe">
|
|
101
|
+
{tipe.map((t) => (
|
|
102
|
+
<TombolTipe key={t} t={t} klik={() => pilih([baru(t)])} />
|
|
103
|
+
))}
|
|
104
|
+
</div>
|
|
105
|
+
) : (
|
|
106
|
+
URUTAN_GRUP.map((g) => {
|
|
107
|
+
const isi = tipe.filter((t) => DEF[t].grup === g);
|
|
108
|
+
return isi.length === 0 ? null : (
|
|
109
|
+
<div key={g} className="u-eb-grup">
|
|
110
|
+
<p className="u-eb-grup-judul">{g}</p>
|
|
111
|
+
<div className="u-eb-kisi-tipe">
|
|
112
|
+
{isi.map((t) => (
|
|
113
|
+
<TombolTipe key={t} t={t} klik={() => pilih([baru(t)])} />
|
|
114
|
+
))}
|
|
115
|
+
</div>
|
|
116
|
+
</div>
|
|
117
|
+
);
|
|
118
|
+
})
|
|
119
|
+
))}
|
|
120
|
+
{tab === 'pola' &&
|
|
121
|
+
(grupPola.length === 0 ? (
|
|
122
|
+
<p className="u-eb-kosong">Belum ada pola. Simpan tulisan sebagai pola dari menu editor.</p>
|
|
123
|
+
) : (
|
|
124
|
+
grupPola.map(([kat, daftar]) => (
|
|
125
|
+
<div key={kat} className="u-eb-grup">
|
|
126
|
+
<p className="u-eb-grup-judul">{kat}</p>
|
|
127
|
+
{daftar.map((p) => (
|
|
128
|
+
<button key={p.id} type="button" className="u-eb-pola" onClick={() => pilih(blokPola(p))}>
|
|
129
|
+
<strong>{p.nama}</strong>
|
|
130
|
+
{p.deskripsi && <span>{p.deskripsi}</span>}
|
|
131
|
+
</button>
|
|
132
|
+
))}
|
|
133
|
+
</div>
|
|
134
|
+
))
|
|
135
|
+
))}
|
|
136
|
+
</div>
|
|
137
|
+
</div>,
|
|
138
|
+
document.body,
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function TombolTipe({ t, klik }: { t: TipeBlok; klik: () => void }) {
|
|
143
|
+
const d = DEF[t];
|
|
144
|
+
const I = d.ikon;
|
|
145
|
+
return (
|
|
146
|
+
<button type="button" onClick={klik} title={d.deskripsi} className="u-eb-tipe">
|
|
147
|
+
<I aria-hidden />
|
|
148
|
+
{d.label}
|
|
149
|
+
</button>
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** Menu garis miring: daftar tipe hasil saring dengan sorotan aktif (navigasi diatur paragraf). */
|
|
154
|
+
export function MenuGaris({ tipe, aktif, pilih }: { tipe: TipeBlok[]; aktif: number; pilih: (t: TipeBlok) => void }) {
|
|
155
|
+
if (tipe.length === 0) return null;
|
|
156
|
+
return (
|
|
157
|
+
<div className="u-eb-menu-garis" role="listbox" contentEditable={false}>
|
|
158
|
+
{tipe.slice(0, 8).map((t, i) => {
|
|
159
|
+
const d = DEF[t];
|
|
160
|
+
const I = d.ikon;
|
|
161
|
+
return (
|
|
162
|
+
<button
|
|
163
|
+
key={t}
|
|
164
|
+
type="button"
|
|
165
|
+
role="option"
|
|
166
|
+
aria-selected={i === aktif}
|
|
167
|
+
className={cn('u-eb-menu-garis-item')}
|
|
168
|
+
onMouseDown={(e) => {
|
|
169
|
+
e.preventDefault();
|
|
170
|
+
pilih(t);
|
|
171
|
+
}}
|
|
172
|
+
>
|
|
173
|
+
<span className="u-eb-menu-garis-ikon">
|
|
174
|
+
<I aria-hidden />
|
|
175
|
+
</span>
|
|
176
|
+
<span>
|
|
177
|
+
<strong>{d.label}</strong>
|
|
178
|
+
<small>{d.deskripsi}</small>
|
|
179
|
+
</span>
|
|
180
|
+
</button>
|
|
181
|
+
);
|
|
182
|
+
})}
|
|
183
|
+
</div>
|
|
184
|
+
);
|
|
185
|
+
}
|