gioser-web: fix graph not appearing — use MutationObserver

- cytoscape-graph.js now uses MutationObserver, not DOMContentLoaded
  (the <gioser-graph> element is created dynamically by WASM)
- Remove unused dispatchEvent from lib.rs
- Rebuild WASM
This commit is contained in:
Sergio
2026-05-23 15:22:13 +00:00
parent d4c31d70b7
commit a908d8420c
7 changed files with 188 additions and 764 deletions
+146 -130
View File
@@ -1,11 +1,11 @@
/**
* gioser-graph.js — Grafo semántico con Cytoscape.js
*
* Se monta automáticamente cuando hay un contenedor <gioser-graph>
* en el DOM con atributo data-api-url.
* Detecta automáticamente elementos <gioser-graph> agregados al DOM
* (incluso los creados dinámicamente por el WASM) y monta el grafo.
*
* Efecto "wineandcheesemap": clic en nodo → centra + desvanece resto.
* Doble clic → callback de navegación.
* Doble clic → callback de navegación (window.__gioserGraphNavigate).
*/
(function () {
@@ -28,74 +28,93 @@
const apiUrl = container.getAttribute('data-api-url') || 'https://api.gioser.net';
const onNavigate = window.__gioserGraphNavigate || null;
fetch(`${apiUrl}/graph?limit=500`)
.then(r => r.json())
.then(data => {
// Si cytoscape no ha cargado, esperar
if (typeof cytoscape === 'undefined') {
const check = setInterval(() => {
if (typeof cytoscape !== 'undefined') {
clearInterval(check);
initGraph(container);
}
}, 100);
return;
}
fetch(apiUrl + '/graph?limit=500')
.then(function (r) { return r.json(); })
.then(function (data) {
if (!data.nodes || data.nodes.length === 0) return;
// Construir elementos Cytoscape
const elements = [];
var elements = [];
for (const n of data.nodes) {
const d = n.data;
for (var i = 0; i < data.nodes.length; i++) {
var d = data.nodes[i].data;
if (!d.doc_id) continue;
const color = caminoColor(d.camino);
var color = caminoColor(d.camino);
elements.push({
group: 'nodes',
data: {
id: d.id,
doc_id: d.doc_id,
label: d.name.length > 22 ? d.name.slice(0, 20) + '…' : d.name,
label: d.name.length > 24 ? d.name.slice(0, 22) + '…' : d.name,
camino: d.camino.toUpperCase(),
color,
color: color,
},
});
}
const nodeIds = new Set(elements.map(e => e.data.id));
var nodeIds = {};
for (var i = 0; i < elements.length; i++) {
nodeIds[elements[i].data.id] = true;
}
for (const e of data.edges) {
const ed = e.data;
if (!nodeIds.has(ed.source) || !nodeIds.has(ed.target)) continue;
const weight = ed.weight || 0.7;
for (var i = 0; i < data.edges.length; i++) {
var ed = data.edges[i].data;
if (!nodeIds[ed.source] || !nodeIds[ed.target]) continue;
var weight = ed.weight || 0.7;
elements.push({
group: 'edges',
data: {
id: ed.id,
source: ed.source,
target: ed.target,
weight,
weight: weight,
},
});
}
const cy = cytoscape({
container,
elements,
// Guardar payload completo para tooltip
var tipMap = {};
for (var i = 0; i < data.nodes.length; i++) {
var d = data.nodes[i].data;
if (d.doc_id) tipMap[d.id] = d;
}
var cy = cytoscape({
container: container,
elements: elements,
style: [
// Aristas: grosor según peso
{
selector: 'edge',
style: {
'width': 'mapData(weight, 0.5, 1.0, 0.5, 4)',
'line-color': 'rgba(255,255,255,0.18)',
'target-arrow-color': 'rgba(255,255,255,0.12)',
'width': 'mapData(weight, 0.5, 1.0, 0.5, 4.5)',
'line-color': 'rgba(255,255,255,0.16)',
'curve-style': 'haystack',
'haystack-radius': 0,
'opacity': 0.6,
},
},
// Nodo: rectángulo redondeado
{
selector: 'node',
style: {
'shape': 'round-rectangle',
'width': 130,
'height': 32,
'height': 34,
'background-color': 'data(color)',
'background-opacity': 0.20,
'background-opacity': 0.18,
'border-color': 'data(color)',
'border-width': 1.5,
'border-opacity': 0.7,
'color': 'rgba(232,234,245,0.90)',
'border-width': 1.8,
'border-opacity': 0.55,
'color': 'rgba(232,234,245,0.88)',
'font-size': 11,
'font-family': 'Inter, system-ui, sans-serif',
'font-weight': 500,
@@ -103,156 +122,153 @@
'text-halign': 'center',
'label': 'data(label)',
'min-zoomed-font-size': 8,
'shadow-blur': 6,
'shadow-color': 'rgba(0,0,0,0.4)',
'shadow-offset-x': 0,
'shadow-offset-y': 2,
'shadow-opacity': 0.5,
'transition-property': 'background-opacity, border-opacity, shadow-blur',
'transition-duration': 200,
'transition-property': 'background-opacity, border-opacity, border-width',
'transition-duration': 180,
},
},
// Sublabel del camino — lo ponemos como label secundario
// Cytoscape no soporta dos labels nativamente; usamos un
// badge de esquina con la data (camino) en el tooltip.
],
layout: {
name: 'cose',
animate: false,
idealEdgeLength: 160,
nodeRepulsion: 8000,
gravity: 0.25,
numIter: 1000,
idealEdgeLength: 150,
nodeRepulsion: 7000,
gravity: 0.2,
numIter: 800,
fit: true,
padding: 30,
padding: 25,
},
});
// Tooltip con preview al hover
const tips = {};
for (const n of data.nodes) {
const d = n.data;
if (d.doc_id) tips[d.id] = d;
}
// Tooltip
var tooltipEl = document.createElement('div');
tooltipEl.className = 'cy-tooltip';
tooltipEl.style.cssText =
'position:absolute;z-index:10;pointer-events:none;' +
'background:rgba(6,5,13,0.90);color:#e8eaf5;' +
'padding:6px 10px;border-radius:8px;font-size:11px;' +
'font-family:Inter,sans-serif;line-height:1.4;' +
'border:1px solid rgba(255,255,255,0.10);' +
'backdrop-filter:blur(8px);max-width:220px;' +
'opacity:0;transition:opacity 180ms ease;';
container.style.position = 'relative';
container.appendChild(tooltipEl);
let tooltipEl = container.querySelector('.cy-tooltip');
if (!tooltipEl) {
tooltipEl = document.createElement('div');
tooltipEl.className = 'cy-tooltip';
tooltipEl.style.cssText =
'position:absolute;z-index:10;pointer-events:none;' +
'background:rgba(6,5,13,0.88);color:#e8eaf5;' +
'padding:6px 10px;border-radius:8px;font-size:11px;' +
'font-family:Inter,sans-serif;line-height:1.4;' +
'border:1px solid rgba(255,255,255,0.10);' +
'backdrop-filter:blur(8px);max-width:240px;' +
'opacity:0;transition:opacity 180ms ease;';
container.style.position = 'relative';
container.appendChild(tooltipEl);
}
cy.on('mouseover', 'node', (ev) => {
const node = ev.target;
node.style({ 'background-opacity': 0.45, 'border-opacity': 1, 'shadow-blur': 12 });
const tipData = tips[node.id()];
cy.on('mouseover', 'node', function (ev) {
var n = ev.target;
n.style({ 'background-opacity': 0.45, 'border-opacity': 0.9, 'border-width': 2.2 });
var tipData = tipMap[n.id()];
if (tipData && tipData.preview) {
tooltipEl.textContent = tipData.preview.slice(0, 120);
tooltipEl.textContent = tipData.preview.slice(0, 130);
tooltipEl.style.opacity = '1';
}
});
cy.on('mouseout', 'node', (ev) => {
const node = ev.target;
node.style({ 'background-opacity': 0.20, 'border-opacity': 0.7, 'shadow-blur': 6 });
cy.on('mouseout', 'node', function (ev) {
var n = ev.target;
n.style({ 'background-opacity': 0.18, 'border-opacity': 0.55, 'border-width': 1.8 });
tooltipEl.style.opacity = '0';
});
cy.on('mousemove', 'node', (ev) => {
const pos = ev.renderedPosition || { x: 0, y: 0 };
tooltipEl.style.left = (pos.x + 14) + 'px';
tooltipEl.style.top = (pos.y - 10) + 'px';
cy.on('mousemove', function (ev) {
if (tooltipEl.style.opacity === '1') {
var pos = ev.renderedPosition || { x: 0, y: 0 };
tooltipEl.style.left = (pos.x + 14) + 'px';
tooltipEl.style.top = (pos.y - 10) + 'px';
}
});
// Click: centrar nodo + desvanecer resto (wineandcheesemap effect)
cy.on('click', 'node', (ev) => {
const node = ev.target;
// Animar vecindario: opacidad plena en nodo + vecinos
cy.nodes().not(node).not(node.neighborhood()).forEach(n => {
n.style({ 'opacity': 0.15 });
// Click nodo: centrar + desvanecer resto
cy.on('click', 'node', function (ev) {
var node = ev.target;
// Vecinos
cy.nodes().not(node).not(node.neighborhood()).forEach(function (n) {
n.style({ 'opacity': 0.12 });
});
cy.edges().forEach(e => {
e.style({ 'opacity': 0.08 });
cy.edges().forEach(function (e) {
e.style({ 'opacity': 0.06 });
});
// Vecinos directos opacidad normal
node.neighborhood().nodes().forEach(n => {
node.neighborhood().nodes().forEach(function (n) {
n.style({ 'opacity': 1 });
});
node.style({ 'opacity': 1 });
// Aristas del vecindario visibles
node.connectedEdges().forEach(e => {
node.style({ 'opacity': 1, 'background-opacity': 0.40, 'border-opacity': 1 });
node.connectedEdges().forEach(function (e) {
e.style({ 'opacity': 0.7 });
});
// Centrar
cy.animate({
center: { eles: node },
zoom: 2.2,
duration: 400,
zoom: 2.5,
duration: 350,
});
});
// Doble clic: navegar a la página
cy.on('dblclick', 'node', (ev) => {
const docId = ev.target.data('doc_id');
// Doble clic: callback de navegación
cy.on('dblclick', 'node', function (ev) {
var docId = ev.target.data('doc_id');
if (onNavigate && docId) onNavigate(docId);
});
// Clic en fondo: restaurar todo
cy.on('click', (ev) => {
cy.on('click', function (ev) {
if (ev.target === cy) {
cy.nodes().forEach(n => n.style({ 'opacity': 1 }));
cy.edges().forEach(e => e.style({ 'opacity': 0.6 }));
cy.nodes().forEach(function (n) {
n.style({ 'opacity': 1, 'background-opacity': 0.18, 'border-opacity': 0.55, 'border-width': 1.8 });
});
cy.edges().forEach(function (e) {
e.style({ 'opacity': 0.6 });
});
cy.animate({ zoom: 1, pan: { x: 0, y: 0 }, duration: 300 });
}
});
// Resize al cambiar tamaño del contenedor
const ro = new ResizeObserver(() => cy.resize().fit(30));
// ResizeObserver para redimensionar con el contenedor
var ro = new ResizeObserver(function () {
cy.resize().fit(25);
});
ro.observe(container);
// Scroll del contenedor padre: pausar interacción si no visible
container.__cy = cy;
// Scroll del deck: pausar interacciones del grafo
var deckEl = container.closest('.deck');
if (deckEl) {
deckEl.addEventListener('scroll', function () {
// No hacemos nada especial, el grafo se redimensiona solo
});
}
})
.catch(err => {
console.warn('gioser-graph: error fetching graph:', err);
.catch(function (err) {
console.warn('gioser-graph: error:', err);
container.innerHTML =
'<div style="padding:1rem;text-align:center;color:rgba(232,234,245,0.35);' +
'<div style="padding:1rem;text-align:center;color:rgba(232,234,245,0.30);' +
'font-size:0.8rem;font-family:Inter,sans-serif;">' +
'· grafo no disponible ·</div>';
});
}
// Auto-inicializar todos los <gioser-graph> en la página
function boot() {
const els = document.querySelectorAll('gioser-graph');
for (const el of els) {
// Esperar a que Cytoscape esté cargado
if (typeof cytoscape !== 'undefined') {
initGraph(el);
} else {
// Si el CDN no ha cargado, esperar
const check = setInterval(() => {
if (typeof cytoscape !== 'undefined') {
clearInterval(check);
initGraph(el);
}
}, 100);
// MutationObserver: detecta <gioser-graph> agregados en cualquier momento
var observer = new MutationObserver(function (mutations) {
for (var m = 0; m < mutations.length; m++) {
var added = mutations[m].addedNodes;
for (var i = 0; i < added.length; i++) {
var el = added[i];
if (el.tagName && el.tagName.toLowerCase() === 'gioser-graph') {
initGraph(el);
}
// También revisar hijos
var graphs = el.querySelectorAll ? el.querySelectorAll('gioser-graph') : [];
for (var j = 0; j < graphs.length; j++) {
initGraph(graphs[j]);
}
}
}
}
});
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', boot);
} else {
boot();
observer.observe(document.documentElement, {
childList: true,
subtree: true,
});
// También inicializar los que ya existen (si el DOM ya está listo)
var existing = document.querySelectorAll('gioser-graph');
for (var i = 0; i < existing.length; i++) {
initGraph(existing[i]);
}
})();
+7 -7
View File
@@ -8,13 +8,13 @@ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembl
export interface InitOutput {
readonly memory: WebAssembly.Memory;
readonly boot: () => void;
readonly __wasm_bindgen_func_elem_178: (a: number, b: number, c: number) => void;
readonly __wasm_bindgen_func_elem_1209: (a: number, b: number, c: number, d: number) => void;
readonly __wasm_bindgen_func_elem_177: (a: number, b: number, c: number) => void;
readonly __wasm_bindgen_func_elem_177_3: (a: number, b: number, c: number) => void;
readonly __wasm_bindgen_func_elem_446: (a: number, b: number, c: number) => void;
readonly __wasm_bindgen_func_elem_223: (a: number, b: number, c: number) => void;
readonly __wasm_bindgen_func_elem_224: (a: number, b: number) => void;
readonly __wasm_bindgen_func_elem_175: (a: number, b: number, c: number) => void;
readonly __wasm_bindgen_func_elem_1203: (a: number, b: number, c: number, d: number) => void;
readonly __wasm_bindgen_func_elem_174: (a: number, b: number, c: number) => void;
readonly __wasm_bindgen_func_elem_174_3: (a: number, b: number, c: number) => void;
readonly __wasm_bindgen_func_elem_442: (a: number, b: number, c: number) => void;
readonly __wasm_bindgen_func_elem_219: (a: number, b: number, c: number) => void;
readonly __wasm_bindgen_func_elem_220: (a: number, b: number) => void;
readonly __wbindgen_export: (a: number, b: number) => number;
readonly __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
readonly __wbindgen_export3: (a: number) => void;
+25 -105
View File
@@ -11,13 +11,6 @@ function __wbg_get_imports() {
const ret = typeof(v) === 'boolean' ? v : undefined;
return isLikeNone(ret) ? 0xFFFFFF : ret ? 1 : 0;
},
__wbg___wbindgen_debug_string_edece8177ad01481: function(arg0, arg1) {
const ret = debugString(getObject(arg1));
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
const len1 = WASM_VECTOR_LEN;
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
},
__wbg___wbindgen_is_function_5cd60d5cf78b4eef: function(arg0) {
const ret = typeof(getObject(arg0)) === 'function';
return ret;
@@ -148,10 +141,6 @@ function __wbg_get_imports() {
__wbg_disable_df908054ffee7971: function(arg0, arg1) {
getObject(arg0).disable(arg1 >>> 0);
},
__wbg_dispatchEvent_29c919cea8d37995: function() { return handleError(function (arg0, arg1) {
const ret = getObject(arg0).dispatchEvent(getObject(arg1));
return ret;
}, arguments); },
__wbg_document_3540635616a18455: function(arg0) {
const ret = getObject(arg0).document;
return isLikeNone(ret) ? 0 : addHeapObject(ret);
@@ -343,10 +332,6 @@ function __wbg_get_imports() {
const ret = new Object();
return addHeapObject(ret);
},
__wbg_new_de9891da0bd35168: function() { return handleError(function (arg0, arg1) {
const ret = new Event(getStringFromWasm0(arg0, arg1));
return addHeapObject(ret);
}, arguments); },
__wbg_ok_556a55299dd238ba: function(arg0) {
const ret = getObject(arg0).ok;
return ret;
@@ -507,38 +492,38 @@ function __wbg_get_imports() {
return ret;
},
__wbindgen_cast_0000000000000001: function(arg0, arg1) {
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 130, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_1209);
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 128, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_1203);
return addHeapObject(ret);
},
__wbindgen_cast_0000000000000002: function(arg0, arg1) {
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [F64], shim_idx: 2, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_178);
const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_175);
return addHeapObject(ret);
},
__wbindgen_cast_0000000000000003: function(arg0, arg1) {
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("Event")], shim_idx: 6, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_177);
const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_174);
return addHeapObject(ret);
},
__wbindgen_cast_0000000000000004: function(arg0, arg1) {
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("KeyboardEvent")], shim_idx: 6, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_177_3);
const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_174_3);
return addHeapObject(ret);
},
__wbindgen_cast_0000000000000005: function(arg0, arg1) {
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("MouseEvent")], shim_idx: 124, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_446);
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("MouseEvent")], shim_idx: 122, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_442);
return addHeapObject(ret);
},
__wbindgen_cast_0000000000000006: function(arg0, arg1) {
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("PointerEvent")], shim_idx: 53, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_223);
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("PointerEvent")], shim_idx: 51, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_219);
return addHeapObject(ret);
},
__wbindgen_cast_0000000000000007: function(arg0, arg1) {
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [], shim_idx: 55, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_224);
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [], shim_idx: 53, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_220);
return addHeapObject(ret);
},
__wbindgen_cast_0000000000000008: function(arg0, arg1) {
@@ -565,30 +550,30 @@ function __wbg_get_imports() {
};
}
function __wasm_bindgen_func_elem_224(arg0, arg1) {
wasm.__wasm_bindgen_func_elem_224(arg0, arg1);
function __wasm_bindgen_func_elem_220(arg0, arg1) {
wasm.__wasm_bindgen_func_elem_220(arg0, arg1);
}
function __wasm_bindgen_func_elem_177(arg0, arg1, arg2) {
wasm.__wasm_bindgen_func_elem_177(arg0, arg1, addHeapObject(arg2));
function __wasm_bindgen_func_elem_174(arg0, arg1, arg2) {
wasm.__wasm_bindgen_func_elem_174(arg0, arg1, addHeapObject(arg2));
}
function __wasm_bindgen_func_elem_177_3(arg0, arg1, arg2) {
wasm.__wasm_bindgen_func_elem_177_3(arg0, arg1, addHeapObject(arg2));
function __wasm_bindgen_func_elem_174_3(arg0, arg1, arg2) {
wasm.__wasm_bindgen_func_elem_174_3(arg0, arg1, addHeapObject(arg2));
}
function __wasm_bindgen_func_elem_446(arg0, arg1, arg2) {
wasm.__wasm_bindgen_func_elem_446(arg0, arg1, addHeapObject(arg2));
function __wasm_bindgen_func_elem_442(arg0, arg1, arg2) {
wasm.__wasm_bindgen_func_elem_442(arg0, arg1, addHeapObject(arg2));
}
function __wasm_bindgen_func_elem_223(arg0, arg1, arg2) {
wasm.__wasm_bindgen_func_elem_223(arg0, arg1, addHeapObject(arg2));
function __wasm_bindgen_func_elem_219(arg0, arg1, arg2) {
wasm.__wasm_bindgen_func_elem_219(arg0, arg1, addHeapObject(arg2));
}
function __wasm_bindgen_func_elem_1209(arg0, arg1, arg2) {
function __wasm_bindgen_func_elem_1203(arg0, arg1, arg2) {
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
wasm.__wasm_bindgen_func_elem_1209(retptr, arg0, arg1, addHeapObject(arg2));
wasm.__wasm_bindgen_func_elem_1203(retptr, arg0, arg1, addHeapObject(arg2));
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
if (r1) {
@@ -599,8 +584,8 @@ function __wasm_bindgen_func_elem_1209(arg0, arg1, arg2) {
}
}
function __wasm_bindgen_func_elem_178(arg0, arg1, arg2) {
wasm.__wasm_bindgen_func_elem_178(arg0, arg1, arg2);
function __wasm_bindgen_func_elem_175(arg0, arg1, arg2) {
wasm.__wasm_bindgen_func_elem_175(arg0, arg1, arg2);
}
function addHeapObject(obj) {
@@ -616,71 +601,6 @@ const CLOSURE_DTORS = (typeof FinalizationRegistry === 'undefined')
? { register: () => {}, unregister: () => {} }
: new FinalizationRegistry(state => wasm.__wbindgen_export4(state.a, state.b));
function debugString(val) {
// primitive types
const type = typeof val;
if (type == 'number' || type == 'boolean' || val == null) {
return `${val}`;
}
if (type == 'string') {
return `"${val}"`;
}
if (type == 'symbol') {
const description = val.description;
if (description == null) {
return 'Symbol';
} else {
return `Symbol(${description})`;
}
}
if (type == 'function') {
const name = val.name;
if (typeof name == 'string' && name.length > 0) {
return `Function(${name})`;
} else {
return 'Function';
}
}
// objects
if (Array.isArray(val)) {
const length = val.length;
let debug = '[';
if (length > 0) {
debug += debugString(val[0]);
}
for(let i = 1; i < length; i++) {
debug += ', ' + debugString(val[i]);
}
debug += ']';
return debug;
}
// Test for built-in
const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
let className;
if (builtInMatches && builtInMatches.length > 1) {
className = builtInMatches[1];
} else {
// Failed to match the standard '[object ClassName]'
return toString.call(val);
}
if (className == 'Object') {
// we're a user defined class or Object
// JSON.stringify avoids problems with cycles, and is generally much
// easier than looping through ownProperties of `val`.
try {
return 'Object(' + JSON.stringify(val) + ')';
} catch (_) {
return 'Object';
}
}
// errors
if (val instanceof Error) {
return `${val.name}: ${val.message}\n${val.stack}`;
}
// TODO we could test for more things here, like `Set`s and `Map`s.
return className;
}
function dropObject(idx) {
if (idx < 1028) return;
heap[idx] = heap_next;
Binary file not shown.
+7 -7
View File
@@ -2,13 +2,13 @@
/* eslint-disable */
export const memory: WebAssembly.Memory;
export const boot: () => void;
export const __wasm_bindgen_func_elem_178: (a: number, b: number, c: number) => void;
export const __wasm_bindgen_func_elem_1209: (a: number, b: number, c: number, d: number) => void;
export const __wasm_bindgen_func_elem_177: (a: number, b: number, c: number) => void;
export const __wasm_bindgen_func_elem_177_3: (a: number, b: number, c: number) => void;
export const __wasm_bindgen_func_elem_446: (a: number, b: number, c: number) => void;
export const __wasm_bindgen_func_elem_223: (a: number, b: number, c: number) => void;
export const __wasm_bindgen_func_elem_224: (a: number, b: number) => void;
export const __wasm_bindgen_func_elem_175: (a: number, b: number, c: number) => void;
export const __wasm_bindgen_func_elem_1203: (a: number, b: number, c: number, d: number) => void;
export const __wasm_bindgen_func_elem_174: (a: number, b: number, c: number) => void;
export const __wasm_bindgen_func_elem_174_3: (a: number, b: number, c: number) => void;
export const __wasm_bindgen_func_elem_442: (a: number, b: number, c: number) => void;
export const __wasm_bindgen_func_elem_219: (a: number, b: number, c: number) => void;
export const __wasm_bindgen_func_elem_220: (a: number, b: number) => void;
export const __wbindgen_export: (a: number, b: number) => number;
export const __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
export const __wbindgen_export3: (a: number) => void;
+3 -6
View File
@@ -306,12 +306,9 @@ impl AppState {
wrapper.style().set_property("border-top", "1px solid rgba(255,255,255,0.06)").ok();
wrapper.style().set_property("min-height", "220px").ok();
content_clone.append_child(&wrapper).ok();
// Disparar el script de Cytoscape si ya está en la página
if let Some(win) = web_sys::window() {
let _ = win.dispatch_event(
&web_sys::Event::new("gioser-graph-ready").unwrap()
);
}
// El script cytoscape-graph.js usa MutationObserver
// para detectar <gioser-graph> dinámicos. No hace falta
// disparar nada acá.
});
}