big cmap refactoring

This commit is contained in:
2026-09-03 08:40:15 +02:00
parent f0562a06cc
commit 2c141b6d3f
32 changed files with 5616 additions and 4216 deletions
+24 -9
View File
@@ -152,7 +152,6 @@ export class CmapWorkspace {
viewport.append(canvas);
embed.append(header, viewport);
const editor = window.RacketWikiCmap.createEditor(canvas, {
Cmap: window.Cmap,
renderItem: (record) => cmapNodeHtml(record),
onOpenExternalUrl: (record) => openCmapExternalUrl(record)
});
@@ -349,6 +348,22 @@ export class CmapWorkspace {
return true;
}
function openLinkedCmap(record) {
if (!record || !record.cmapSlug) return false;
navigateToHash(cmapRoute(record.cmapSlug)).catch((error) => console.error(error));
return true;
}
function openParentCmap() {
const source = state.currentConceptMapSource;
if (source && source.slug) {
navigateToHash(cmapRoute(source.slug)).catch((error) => console.error(error));
return true;
}
const prototype = cmapPrototypeState();
return Boolean(prototype.editor && prototype.editor.openParentMap());
}
function titledCmapComboboxEntry(record) {
const label = record.title || record.slug;
return {
@@ -726,7 +741,6 @@ export class CmapWorkspace {
updateCmapSelectionToolbar(null, [], null);
console.info("[racket-wiki:cmap-host 0.2.122] resetCmapPrototype", {
cmapAvailable: typeof window.Cmap === "function",
interactionLayerAvailable: Boolean(window.RacketWikiCmap),
interactionLayerVersion: window.RacketWikiCmap ? window.RacketWikiCmap.version : null,
cmapStylesheet: Array.from(document.styleSheets)
@@ -734,7 +748,7 @@ export class CmapWorkspace {
.find((href) => href && href.includes("/cmap/cmap.css")) || null
});
if (typeof window.Cmap !== "function" || !window.RacketWikiCmap) {
if (!window.RacketWikiCmap) {
const message = document.createElement("p");
message.className = "error";
message.textContent = "The bundled cmap component could not be loaded.";
@@ -744,7 +758,6 @@ export class CmapWorkspace {
const prototype = cmapPrototypeState();
prototype.editor = window.RacketWikiCmap.createEditor(canvas, {
Cmap: window.Cmap,
renderItem: (record) => cmapNodeHtml(record),
onOpenPage: (record) => {
if (record.pageSlug) {
@@ -752,9 +765,10 @@ export class CmapWorkspace {
}
},
onOpenCmap: (record) => {
if (record.cmapSlug) {
navigateToHash(cmapRoute(record.cmapSlug)).catch((error) => console.error(error));
}
openLinkedCmap(record);
},
onOpenParentCmap: () => {
openParentCmap();
},
onOpenExternalUrl: (record) => openCmapExternalUrl(record),
onOpenStoredSubMap: (record) => {
@@ -1699,7 +1713,7 @@ export class CmapWorkspace {
markCurrentCmapSaved();
}
});
$("cmap-map-back").addEventListener("click", () => {
const navigateToParentCmap = () => {
const prototype = cmapPrototypeState();
if (prototype.editor && prototype.editor.canStepBackWithinMap()) {
prototype.editor.openParentMap();
@@ -1711,7 +1725,8 @@ export class CmapWorkspace {
return;
}
if (prototype.editor) prototype.editor.openParentMap();
});
};
$("cmap-map-navigation").addEventListener("click", navigateToParentCmap);
$("cmap-canvas").addEventListener("contextmenu", (event) => {
event.preventDefault();
const prototype = cmapPrototypeState();