Hi. First i appology for my freaking English level.
actually its first time in my life writing long text in foregin language. (it so awkward and scared…)
I aready search and study all day but i cant solve this problem and my dissatisfaction is grow up…and i can’t upload screenshot too;;;;;;
What I’m trying to do
;(() => {
// ========= 안전 가드 =========
if (!ea || !ea.getElements) {
try { new Notice("Excalidraw View에서 실행해주세요."); } catch (_) {}
console.log("[Excalidraw] Run this in Excalidraw view.");
return;
}
if (!ea.verifyMinimumPluginVersion || !ea.verifyMinimumPluginVersion("1.5.21")) {
try { new Notice("Excalidraw 1.5.21 이상이 필요합니다."); } catch (_) {}
return;
}
// ========= 유틸 =========
function notify(msg) {
try { new Notice(String(msg)); }
catch (_) { try { ea.addText(0, 0, String(msg)); } catch(__) {} console.log("[NOTICE]", msg); }
}
const SHAPES = new Set(["rectangle", "ellipse", "diamond", "circle"]);
const all = ea.getElements();
function pickAnchor(el) {
// 그룹이 있으면: 도형 → 텍스트 → 아무거나
const gids = el.groupIds ?? [];
if (!gids.length) return el;
const group = all.filter(e => (e.groupIds ?? []).some(id => gids.includes(id)));
return group.find(e => SHAPES.has(e.type))
?? group.find(e => e.type === "text")
?? group[0]
?? el;
}
// 허브 ID 보관(전역; Obsidian에서 localStorage 이슈 회피)
const HUB_SLOT = "_ex_hub_id";
function setHubId(id) { window[HUB_SLOT] = id; }
function getHubId() { return window[HUB_SLOT]; }
function clearHub() { delete window[HUB_SLOT]; }
// ========= 본동작: 토글 =========
const sel = ea.getSelectedElements();
const hubId = getHubId();
// 1) 허브가 아직 없으면 → 지금 선택을 허브로 '지정'
if (!hubId) {
if (sel.length !== 1) {
notify("허브로 삼을 요소 하나를 선택한 뒤 실행하세요.");
return;
}
const hubAnchor = pickAnchor(sel[0]);
setHubId(hubAnchor.id);
notify("허브 지정 완료: " + hubAnchor.type);
return;
}
// 2) 허브가 있으면 → 현재 선택들을 허브에 '연결'
const hub = all.find(e => e.id === hubId);
if (!hub) {
clearHub();
notify("저장된 허브를 찾지 못했습니다. 다시 허브를 지정하세요.");
return;
}
const targets = sel.filter(e => e.id !== hubId);
if (!targets.length) {
notify("허브에 연결할 대상(하나 이상)을 선택한 뒤 다시 실행하세요.");
return;
}
// 스타일: 허브(대표)의 선 스타일을 따르도록(원치 않으면 제거)
ea.style.strokeColor = hub.strokeColor;
ea.style.strokeWidth = hub.strokeWidth;
ea.style.strokeStyle = hub.strokeStyle;
if (typeof hub.strokeSharpness !== "undefined") {
ea.style.strokeSharpness = hub.strokeSharpness;
}
if (typeof hub.roundness !== "undefined") {
ea.style.roundness = hub.roundness;
}
const hubAnchor = pickAnchor(hub);
const opts = {
numberOfPoints: 0,
startArrowHead: null,
endArrowHead: "arrow",
padding: 8
};
for (const raw of targets) {
const t = pickAnchor(raw);
// fromSide/toSide를 null → Excalidraw가 "가까운 변"으로 자동 앵커 선택
ea.connectObjects(hubAnchor.id, null, t.id, null, opts);
}
ea.addElementsToView();
notify("허브에서 " + targets.length + "개 연결 완료");
// 연결 후 허브 유지하고 싶으면 주석 해제
clearHub();
})();
Actually i’m super begginer from coding. So i get help from GPT. But i was search code that use in Excalidraw too and study their meaning.
However consol said their is “await in eval” error. I think their is inapposite use of “”.
My original intention is when i select a piece of element, example A, and enter hotkey, system save root element naming hub. Then i select multiple element that i want specify subconcept. And then i enter hotkey again. If so, the main concept, A is connect with multiple subconcept with line, like a mindmap.
I know im so stupide and lazzy. I want to upgrade my prigramming skill and to approve my goal, i will study constantly. Please give me more advice and help. if you so, i will verry appreciate for your kindness.