@kgdiff/viewer 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/README.md +52 -2
- package/dist/compute-loader.d.ts +13 -0
- package/dist/compute-loader.d.ts.map +1 -0
- package/dist/compute-loader.js +46 -0
- package/dist/compute-loader.js.map +1 -0
- package/dist/compute.d.ts +8 -0
- package/dist/compute.d.ts.map +1 -0
- package/dist/compute.js +8 -0
- package/dist/compute.js.map +1 -0
- package/dist/controller.d.ts +199 -0
- package/dist/controller.d.ts.map +1 -0
- package/dist/controller.js +1254 -0
- package/dist/controller.js.map +1 -0
- package/dist/dom.d.ts +32 -0
- package/dist/dom.d.ts.map +1 -0
- package/dist/dom.js +105 -0
- package/dist/dom.js.map +1 -0
- package/dist/element.d.ts +43 -0
- package/dist/element.d.ts.map +1 -0
- package/dist/element.js +656 -0
- package/dist/element.js.map +1 -0
- package/dist/framing.d.ts +45 -0
- package/dist/framing.d.ts.map +1 -0
- package/dist/framing.js +107 -0
- package/dist/framing.js.map +1 -0
- package/dist/hash-sync.d.ts +18 -0
- package/dist/hash-sync.d.ts.map +1 -0
- package/dist/hash-sync.js +45 -0
- package/dist/hash-sync.js.map +1 -0
- package/dist/i18n.d.ts +222 -0
- package/dist/i18n.d.ts.map +1 -0
- package/dist/i18n.js +434 -0
- package/dist/i18n.js.map +1 -0
- package/dist/icons.d.ts +37 -0
- package/dist/icons.d.ts.map +1 -0
- package/dist/icons.js +36 -0
- package/dist/icons.js.map +1 -0
- package/dist/index.d.ts +151 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +41 -0
- package/dist/index.js.map +1 -0
- package/dist/keyboard.d.ts +64 -0
- package/dist/keyboard.d.ts.map +1 -0
- package/dist/keyboard.js +95 -0
- package/dist/keyboard.js.map +1 -0
- package/dist/list-model.d.ts +35 -0
- package/dist/list-model.d.ts.map +1 -0
- package/dist/list-model.js +70 -0
- package/dist/list-model.js.map +1 -0
- package/dist/payload.d.ts +10 -0
- package/dist/payload.d.ts.map +1 -0
- package/dist/payload.js +138 -0
- package/dist/payload.js.map +1 -0
- package/dist/pipeline.d.ts +31 -0
- package/dist/pipeline.d.ts.map +1 -0
- package/dist/pipeline.js +122 -0
- package/dist/pipeline.js.map +1 -0
- package/dist/prefs.d.ts +18 -0
- package/dist/prefs.d.ts.map +1 -0
- package/dist/prefs.js +38 -0
- package/dist/prefs.js.map +1 -0
- package/dist/registry.d.ts +3 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +3 -0
- package/dist/registry.js.map +1 -0
- package/dist/renderer-port.d.ts +14 -0
- package/dist/renderer-port.d.ts.map +1 -0
- package/dist/renderer-port.js +16 -0
- package/dist/renderer-port.js.map +1 -0
- package/dist/replay.d.ts +55 -0
- package/dist/replay.d.ts.map +1 -0
- package/dist/replay.js +147 -0
- package/dist/replay.js.map +1 -0
- package/dist/review-store.d.ts +30 -0
- package/dist/review-store.d.ts.map +1 -0
- package/dist/review-store.js +120 -0
- package/dist/review-store.js.map +1 -0
- package/dist/search.d.ts +25 -0
- package/dist/search.d.ts.map +1 -0
- package/dist/search.js +90 -0
- package/dist/search.js.map +1 -0
- package/dist/standalone/kgdiff-viewer-compute.js +1 -0
- package/dist/standalone/kgdiff-viewer.js +5 -0
- package/dist/standalone-compute.d.ts +2 -0
- package/dist/standalone-compute.d.ts.map +1 -0
- package/dist/standalone-compute.js +8 -0
- package/dist/standalone-compute.js.map +1 -0
- package/dist/standalone.d.ts +2 -0
- package/dist/standalone.d.ts.map +1 -0
- package/dist/standalone.js +18 -0
- package/dist/standalone.js.map +1 -0
- package/dist/styles.d.ts +11 -0
- package/dist/styles.d.ts.map +1 -0
- package/dist/styles.js +622 -0
- package/dist/styles.js.map +1 -0
- package/dist/text-diff.d.ts +44 -0
- package/dist/text-diff.d.ts.map +1 -0
- package/dist/text-diff.js +261 -0
- package/dist/text-diff.js.map +1 -0
- package/dist/ui/context.d.ts +32 -0
- package/dist/ui/context.d.ts.map +1 -0
- package/dist/ui/context.js +49 -0
- package/dist/ui/context.js.map +1 -0
- package/dist/ui/detail.d.ts +9 -0
- package/dist/ui/detail.d.ts.map +1 -0
- package/dist/ui/detail.js +609 -0
- package/dist/ui/detail.js.map +1 -0
- package/dist/ui/header.d.ts +14 -0
- package/dist/ui/header.d.ts.map +1 -0
- package/dist/ui/header.js +195 -0
- package/dist/ui/header.js.map +1 -0
- package/dist/ui/popovers.d.ts +20 -0
- package/dist/ui/popovers.d.ts.map +1 -0
- package/dist/ui/popovers.js +180 -0
- package/dist/ui/popovers.js.map +1 -0
- package/dist/ui/sidebar.d.ts +25 -0
- package/dist/ui/sidebar.d.ts.map +1 -0
- package/dist/ui/sidebar.js +609 -0
- package/dist/ui/sidebar.js.map +1 -0
- package/dist/ui/stage.d.ts +18 -0
- package/dist/ui/stage.d.ts.map +1 -0
- package/dist/ui/stage.js +664 -0
- package/dist/ui/stage.js.map +1 -0
- package/package.json +58 -3
- package/src/compute-loader.ts +58 -0
- package/src/compute.ts +7 -0
- package/src/controller.ts +1393 -0
- package/src/dom.ts +131 -0
- package/src/element.ts +697 -0
- package/src/framing.ts +150 -0
- package/src/hash-sync.ts +54 -0
- package/src/i18n.ts +467 -0
- package/src/icons.ts +48 -0
- package/src/index.ts +171 -0
- package/src/keyboard.ts +128 -0
- package/src/list-model.ts +86 -0
- package/src/payload.ts +165 -0
- package/src/pipeline.ts +179 -0
- package/src/prefs.ts +55 -0
- package/src/registry.ts +2 -0
- package/src/renderer-port.ts +31 -0
- package/src/replay.ts +163 -0
- package/src/review-store.ts +125 -0
- package/src/search.ts +113 -0
- package/src/standalone-compute.ts +8 -0
- package/src/standalone.ts +18 -0
- package/src/styles.ts +633 -0
- package/src/text-diff.ts +263 -0
- package/src/ui/context.ts +70 -0
- package/src/ui/detail.ts +929 -0
- package/src/ui/header.ts +278 -0
- package/src/ui/popovers.ts +251 -0
- package/src/ui/sidebar.ts +752 -0
- package/src/ui/stage.ts +853 -0
|
@@ -0,0 +1,609 @@
|
|
|
1
|
+
import { attr, h, icon, iconButton, replaceKeepingFocus } from '../dom.js';
|
|
2
|
+
import { formatPercent } from '../i18n.js';
|
|
3
|
+
import { diffChars, diffWords, pairItems } from '../text-diff.js';
|
|
4
|
+
import { formatValue, listItems, sceneHunkGlyph } from './context.js';
|
|
5
|
+
const MAX_NODES = 12;
|
|
6
|
+
const MAX_RELATIONS = 12;
|
|
7
|
+
const CLAMP_CHARS = 180;
|
|
8
|
+
/** Up to this many characters (both sides together) a value change reads `before → after`. */
|
|
9
|
+
const INLINE_CHARS = 60;
|
|
10
|
+
function section(title, count, ...children) {
|
|
11
|
+
return h('section', { class: 'section' }, h('h3', null, title, count !== null ? h('span', { class: 'n', text: String(count) }) : null), ...children);
|
|
12
|
+
}
|
|
13
|
+
function kv(rows) {
|
|
14
|
+
const dl = h('dl', { class: 'kv' });
|
|
15
|
+
for (const [k, v] of rows)
|
|
16
|
+
dl.append(h('dt', { text: k }), h('dd', null, ...[v].flat()));
|
|
17
|
+
return dl;
|
|
18
|
+
}
|
|
19
|
+
/** Render one side of a diff: equal text plus that side's changes marked. */
|
|
20
|
+
function marked(segs, side) {
|
|
21
|
+
const out = [];
|
|
22
|
+
for (const s of segs) {
|
|
23
|
+
if (s.op === 'equal')
|
|
24
|
+
out.push(s.text);
|
|
25
|
+
else if (s.op === 'delete' && side === 'before')
|
|
26
|
+
out.push(h('del', { class: 'hl', text: s.text }));
|
|
27
|
+
else if (s.op === 'insert' && side === 'after')
|
|
28
|
+
out.push(h('ins', { class: 'hl', text: s.text }));
|
|
29
|
+
}
|
|
30
|
+
return out;
|
|
31
|
+
}
|
|
32
|
+
function chip(text, kind) {
|
|
33
|
+
const sign = kind === 'add' ? '+' : kind === 'del' ? '−' : '';
|
|
34
|
+
return h('span', { class: `vchip${kind === 'same' ? '' : ` ${kind}`}` }, sign ? h('span', { class: 'sign', 'aria-hidden': 'true', text: sign }) : null, text);
|
|
35
|
+
}
|
|
36
|
+
function chips(added, removed, same = []) {
|
|
37
|
+
return h('div', { class: 'chips' }, removed.map((x) => chip(x, 'del')), added.map((x) => chip(x, 'add')), same.map((x) => chip(x, 'same')));
|
|
38
|
+
}
|
|
39
|
+
/** `before → after` on one line, wrapping when long. */
|
|
40
|
+
function pair(before, after, tr) {
|
|
41
|
+
return h('div', { class: 'pair' }, h('span', { class: 'b' }, before), h('span', { class: 'arr', 'aria-hidden': 'true', text: '→' }), h('span', { class: 'sr-only', text: tr.t('detail.changedTo') }), h('span', null, after));
|
|
42
|
+
}
|
|
43
|
+
/** `before → after` with the changed characters marked. */
|
|
44
|
+
function textPair(before, after, tr) {
|
|
45
|
+
const segs = diffChars(before, after);
|
|
46
|
+
return pair(marked(segs, 'before'), marked(segs, 'after'), tr);
|
|
47
|
+
}
|
|
48
|
+
/** One side of a change on a line of its own: `− before` or `+ after`. */
|
|
49
|
+
function signed(side, content) {
|
|
50
|
+
return h('div', { class: `line ${side}` }, h('span', { class: 'sign', 'aria-hidden': 'true', text: side === 'old' ? '−' : '+' }), h('div', null, content));
|
|
51
|
+
}
|
|
52
|
+
/** A set change (synonyms, types, parents, list values): edits as pairs, the rest as chips. */
|
|
53
|
+
function items(added, removed, tr, same = []) {
|
|
54
|
+
const p = pairItems(removed, added);
|
|
55
|
+
const out = p.pairs.map(([b, a]) => textPair(b, a, tr));
|
|
56
|
+
if (p.added.length > 0 || p.removed.length > 0 || same.length > 0) {
|
|
57
|
+
out.push(chips(p.added, p.removed, same));
|
|
58
|
+
}
|
|
59
|
+
return out;
|
|
60
|
+
}
|
|
61
|
+
/** Key · value rows. */
|
|
62
|
+
function table(rows, cls = 'attrs') {
|
|
63
|
+
return h('table', { class: cls }, h('colgroup', null, h('col', { class: 'k' }), h('col')), h('tbody', null, rows.map(([k, v]) => h('tr', null, h('td', { class: 'k', text: k }), h('td', null, v)))));
|
|
64
|
+
}
|
|
65
|
+
function familyOfEdge(e) {
|
|
66
|
+
if (e.status === 'added')
|
|
67
|
+
return 'added';
|
|
68
|
+
if (e.status === 'removed') {
|
|
69
|
+
return e.facets.some((f) => f.kind === 'collapsed') ? 'identity' : 'removed';
|
|
70
|
+
}
|
|
71
|
+
for (const f of e.facets) {
|
|
72
|
+
if (f.kind === 'retarget')
|
|
73
|
+
return f.cause === 'merge' || f.cause === 'split' ? 'identity' : 'structure';
|
|
74
|
+
if (f.kind === 'predicate')
|
|
75
|
+
return 'structure';
|
|
76
|
+
}
|
|
77
|
+
return e.status === 'modified' ? 'content' : 'neutral';
|
|
78
|
+
}
|
|
79
|
+
export class Detail {
|
|
80
|
+
el;
|
|
81
|
+
#body;
|
|
82
|
+
#showUnchangedAttrs = false;
|
|
83
|
+
#showAllRelations = false;
|
|
84
|
+
#showAllNodes = false;
|
|
85
|
+
#expandedValues = new Set();
|
|
86
|
+
#lastKey = '';
|
|
87
|
+
#ctx;
|
|
88
|
+
constructor(ctx) {
|
|
89
|
+
this.#ctx = ctx;
|
|
90
|
+
this.#body = h('div', { class: 'detail-scroll scroll', tabindex: '-1' });
|
|
91
|
+
this.el = h('section', { class: 'detail', 'data-empty': 'true' }, this.#body);
|
|
92
|
+
}
|
|
93
|
+
update(topics) {
|
|
94
|
+
if (topics.has('selection') ||
|
|
95
|
+
topics.has('data') ||
|
|
96
|
+
topics.has('locale') ||
|
|
97
|
+
topics.has('review') ||
|
|
98
|
+
topics.has('status') ||
|
|
99
|
+
topics.has('filters')) {
|
|
100
|
+
this.#render();
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
#render() {
|
|
104
|
+
const c = this.#ctx.controller;
|
|
105
|
+
const tr = this.#ctx.tr();
|
|
106
|
+
attr(this.el, 'aria-label', tr.t('detail.label'));
|
|
107
|
+
const scene = c.scene;
|
|
108
|
+
const diff = c.diff;
|
|
109
|
+
this.el.hidden =
|
|
110
|
+
c.status !== 'ready' || !scene || !diff || (scene.hunks.length === 0 && c.selectedNode < 0);
|
|
111
|
+
if (this.el.hidden || !scene || !diff)
|
|
112
|
+
return;
|
|
113
|
+
const key = `${c.selectedHunk}|${c.selectedNode}`;
|
|
114
|
+
if (key !== this.#lastKey) {
|
|
115
|
+
this.#lastKey = key;
|
|
116
|
+
this.#showUnchangedAttrs = false;
|
|
117
|
+
this.#showAllRelations = false;
|
|
118
|
+
this.#showAllNodes = false;
|
|
119
|
+
this.#expandedValues.clear();
|
|
120
|
+
this.#body.scrollTop = 0;
|
|
121
|
+
}
|
|
122
|
+
if (c.selectedHunk < 0 && c.selectedNode < 0) {
|
|
123
|
+
attr(this.el, 'data-empty', 'true');
|
|
124
|
+
replaceKeepingFocus(this.#ctx.root, this.#body, this.#body, h('div', { class: 'detail-empty' }, icon('changes'), h('div', null, h('div', { text: tr.t('detail.empty') }), h('div', { class: 'sub', text: tr.t('detail.emptyHint') }))));
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
attr(this.el, 'data-empty', 'false');
|
|
128
|
+
const hunk = c.selectedHunk >= 0 ? scene.hunks[c.selectedHunk] : undefined;
|
|
129
|
+
if (hunk)
|
|
130
|
+
this.#renderHunk(hunk, scene, diff, tr);
|
|
131
|
+
else
|
|
132
|
+
this.#renderNode(scene, diff, tr);
|
|
133
|
+
}
|
|
134
|
+
#nav(tr, hunk) {
|
|
135
|
+
const c = this.#ctx.controller;
|
|
136
|
+
const items = [];
|
|
137
|
+
if (hunk) {
|
|
138
|
+
const reviewed = c.isReviewed(hunk.id);
|
|
139
|
+
items.push(h('button', {
|
|
140
|
+
type: 'button',
|
|
141
|
+
class: 'rv-btn',
|
|
142
|
+
'data-focus-key': 'review',
|
|
143
|
+
'aria-pressed': String(reviewed),
|
|
144
|
+
title: `${tr.t(reviewed ? 'review.unmark' : 'review.mark')} (X)`,
|
|
145
|
+
onclick: () => c.toggleReviewed(hunk.id),
|
|
146
|
+
}, h('span', { class: 'ring' }, icon('check')), tr.t('review.toggle')));
|
|
147
|
+
}
|
|
148
|
+
const rank = hunk ? c.list.rank.get(hunk.index) : undefined;
|
|
149
|
+
const prev = iconButton('chevron-up', `${tr.t('detail.prev')} (K)`, () => c.prev(), {
|
|
150
|
+
class: 'icon-btn sm',
|
|
151
|
+
'data-focus-key': 'prev',
|
|
152
|
+
});
|
|
153
|
+
const next = iconButton('chevron-down', `${tr.t('detail.next')} (J)`, () => c.next(), {
|
|
154
|
+
class: 'icon-btn sm',
|
|
155
|
+
'data-focus-key': 'next',
|
|
156
|
+
});
|
|
157
|
+
prev.disabled = rank === 0 || c.list.order.length === 0;
|
|
158
|
+
next.disabled =
|
|
159
|
+
(rank !== undefined && rank >= c.list.order.length - 1) || c.list.order.length === 0;
|
|
160
|
+
items.push(prev, next);
|
|
161
|
+
return h('div', { class: 'd-nav' }, ...items);
|
|
162
|
+
}
|
|
163
|
+
#renderHunk(hunk, scene, diff, tr) {
|
|
164
|
+
const c = this.#ctx.controller;
|
|
165
|
+
const core = diff.index.hunk(hunk.id);
|
|
166
|
+
const focusIndex = c.selectedNode >= 0 && hunk.nodes.includes(c.selectedNode) ? c.selectedNode : hunk.anchor;
|
|
167
|
+
const focusId = focusIndex >= 0 ? scene.nodes[focusIndex]?.id : core?.anchor;
|
|
168
|
+
const focus = focusId !== undefined ? diff.index.node(focusId) : undefined;
|
|
169
|
+
const parts = [
|
|
170
|
+
h('div', { class: 'd-top' }, h('span', { class: 'fam-pill', 'data-family': hunk.family }, h('span', { class: 'g', 'aria-hidden': 'true', text: sceneHunkGlyph(hunk) }), tr.t(`kind.${hunk.kind}`)), this.#nav(tr, hunk)),
|
|
171
|
+
h('h2', { class: 'd-title', text: hunk.title }),
|
|
172
|
+
hunk.subtitle ? h('div', { class: 'd-sub', text: hunk.subtitle }) : null,
|
|
173
|
+
];
|
|
174
|
+
const nodeIds = core?.nodes ?? [];
|
|
175
|
+
if (nodeIds.length > 1)
|
|
176
|
+
parts.push(this.#nodeList(nodeIds, focusId, scene, diff, tr));
|
|
177
|
+
const [lead, rest] = focus
|
|
178
|
+
? this.#nodeSections(focus, diff, tr, nodeIds.length > 1, true)
|
|
179
|
+
: [[], []];
|
|
180
|
+
const edges = (core?.edges ?? [])
|
|
181
|
+
.map((id) => diff.index.edge(id))
|
|
182
|
+
.filter((e) => e !== undefined);
|
|
183
|
+
parts.push(...lead);
|
|
184
|
+
if (edges.length > 0)
|
|
185
|
+
parts.push(this.#relations(edges, focusId, scene, diff, tr, true));
|
|
186
|
+
parts.push(...rest);
|
|
187
|
+
replaceKeepingFocus(this.#ctx.root, this.#body, this.#body, ...parts);
|
|
188
|
+
}
|
|
189
|
+
#renderNode(scene, diff, tr) {
|
|
190
|
+
const c = this.#ctx.controller;
|
|
191
|
+
const sn = scene.nodes[c.selectedNode];
|
|
192
|
+
const node = sn ? diff.index.node(sn.id) : undefined;
|
|
193
|
+
if (!sn || !node) {
|
|
194
|
+
replaceKeepingFocus(this.#ctx.root, this.#body, this.#body);
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
const edges = diff.index.edgesOf(node.id);
|
|
198
|
+
const [lead, rest] = this.#nodeSections(node, diff, tr, false, false);
|
|
199
|
+
replaceKeepingFocus(this.#ctx.root, this.#body, this.#body, h('div', { class: 'd-top' }, h('span', { class: 'fam-pill', 'data-family': sn.family }, h('span', { class: 'g', 'aria-hidden': 'true', text: '·' }), tr.t(node.status === 'unchanged' ? 'detail.unchangedNode' : `status.${node.status}`)), this.#nav(tr, undefined)), h('h2', { class: 'd-title', text: node.label }), ...lead, edges.length > 0 ? this.#relations(edges, node.id, scene, diff, tr, false) : null, ...rest);
|
|
200
|
+
}
|
|
201
|
+
// ─── Sections ────────────────────────────────────────────────────────────
|
|
202
|
+
#nodeList(ids, focusId, scene, diff, tr) {
|
|
203
|
+
const c = this.#ctx.controller;
|
|
204
|
+
const shown = this.#showAllNodes ? ids : ids.slice(0, MAX_NODES);
|
|
205
|
+
const list = h('div', { class: 'nodes' });
|
|
206
|
+
for (const id of shown) {
|
|
207
|
+
const n = diff.index.node(id);
|
|
208
|
+
const i = scene.nodeIndex.get(id);
|
|
209
|
+
const fam = i !== undefined ? (scene.nodes[i]?.family ?? 'neutral') : 'neutral';
|
|
210
|
+
list.appendChild(h('button', {
|
|
211
|
+
type: 'button',
|
|
212
|
+
class: 'node-link',
|
|
213
|
+
'data-focus-key': `node:${id}`,
|
|
214
|
+
'data-family': fam,
|
|
215
|
+
'aria-current': String(id === focusId),
|
|
216
|
+
onclick: () => {
|
|
217
|
+
if (i !== undefined)
|
|
218
|
+
c.selectNode(i, { fly: true });
|
|
219
|
+
},
|
|
220
|
+
}, h('span', { class: 'sdot', 'aria-hidden': 'true' }), h('span', { class: 'lbl', text: n?.label ?? id, title: n?.label ?? id }), h('span', { class: 'meta', text: n ? tr.t(`status.${n.status}`) : '' })));
|
|
221
|
+
}
|
|
222
|
+
return section(tr.t('detail.nodes'), ids.length, list, ids.length > MAX_NODES
|
|
223
|
+
? this.#moreToggle(tr, this.#showAllNodes, () => {
|
|
224
|
+
this.#showAllNodes = !this.#showAllNodes;
|
|
225
|
+
this.#render();
|
|
226
|
+
})
|
|
227
|
+
: null);
|
|
228
|
+
}
|
|
229
|
+
#moreToggle(tr, expanded, onClick) {
|
|
230
|
+
return h('button', {
|
|
231
|
+
type: 'button',
|
|
232
|
+
class: 'disclosure',
|
|
233
|
+
'data-focus-key': 'nodes-more',
|
|
234
|
+
'aria-expanded': String(expanded),
|
|
235
|
+
onclick: onClick,
|
|
236
|
+
}, tr.t(expanded ? 'detail.showLess' : 'detail.showMore'), icon('chevron-down'));
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* The node's sections, split around the relations. A modified node (or an unchanged one a hunk
|
|
240
|
+
* points at) leads with what changed and ends with its unchanged rest; added, removed and
|
|
241
|
+
* inspected nodes lead with what they are.
|
|
242
|
+
*/
|
|
243
|
+
#nodeSections(node, diff, tr, showName, inHunk) {
|
|
244
|
+
const label = (id) => diff.index.node(id)?.label ?? id;
|
|
245
|
+
const fold = node.status === 'modified' || (inHunk && node.status === 'unchanged');
|
|
246
|
+
const changes = this.#changes(node, diff, tr, label);
|
|
247
|
+
const comp = this.#composition(node, diff, tr, label);
|
|
248
|
+
const evidence = this.#evidence(node, diff, tr, label);
|
|
249
|
+
const overview = this.#overview(node, tr, showName, fold);
|
|
250
|
+
const present = (xs) => xs.filter((x) => x !== null);
|
|
251
|
+
return fold
|
|
252
|
+
? [present([comp, changes]), present([evidence, ...overview])]
|
|
253
|
+
: [present([...overview, changes, comp, evidence]), []];
|
|
254
|
+
}
|
|
255
|
+
/** What changed on the node: one row per facet (per key for attributes), in facet order. */
|
|
256
|
+
#changes(node, diff, tr, label) {
|
|
257
|
+
// Replacement links hold ids as written: name the node they point at when there is one.
|
|
258
|
+
const named = (ids) => ids.map((id) => (diff.index.nodeByAfter(id) ?? diff.index.nodeByBefore(id))?.label ?? id);
|
|
259
|
+
const rows = [];
|
|
260
|
+
for (const f of node.facets) {
|
|
261
|
+
switch (f.kind) {
|
|
262
|
+
case 'rekey':
|
|
263
|
+
rows.push([
|
|
264
|
+
tr.t('detail.id'),
|
|
265
|
+
[
|
|
266
|
+
h('div', { class: 'id-text' }, textPair(f.from, f.to, tr)),
|
|
267
|
+
f.score < 1
|
|
268
|
+
? h('div', {
|
|
269
|
+
class: 'note-line',
|
|
270
|
+
text: tr.t('detail.matchScore', { p: formatPercent(f.score) }),
|
|
271
|
+
})
|
|
272
|
+
: null,
|
|
273
|
+
],
|
|
274
|
+
]);
|
|
275
|
+
break;
|
|
276
|
+
case 'rename':
|
|
277
|
+
rows.push([tr.t('detail.name'), textPair(f.from, f.to, tr)]);
|
|
278
|
+
break;
|
|
279
|
+
case 'types':
|
|
280
|
+
case 'aliases':
|
|
281
|
+
rows.push([tr.t(`detail.${f.kind}`), items(f.added, f.removed, tr)]);
|
|
282
|
+
break;
|
|
283
|
+
case 'attrs':
|
|
284
|
+
for (const ch of f.changes)
|
|
285
|
+
rows.push([ch.key, this.#attrChange(node.id, ch, tr)]);
|
|
286
|
+
break;
|
|
287
|
+
case 'move':
|
|
288
|
+
rows.push([tr.t('detail.hierarchy'), items(f.to.map(label), f.from.map(label), tr)]);
|
|
289
|
+
break;
|
|
290
|
+
case 'deprecate':
|
|
291
|
+
rows.push([
|
|
292
|
+
tr.t('detail.status'),
|
|
293
|
+
h('strong', {
|
|
294
|
+
text: tr.t(f.deprecated ? 'detail.deprecated' : 'detail.undeprecated'),
|
|
295
|
+
}),
|
|
296
|
+
]);
|
|
297
|
+
break;
|
|
298
|
+
case 'replacement':
|
|
299
|
+
for (const [key, links] of [
|
|
300
|
+
['detail.replacedBy', f.replacedBy],
|
|
301
|
+
['detail.replaces', f.replaces],
|
|
302
|
+
]) {
|
|
303
|
+
if (links.added.length > 0 || links.removed.length > 0) {
|
|
304
|
+
rows.push([tr.t(key), items(named(links.added), named(links.removed), tr)]);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
break;
|
|
308
|
+
default:
|
|
309
|
+
// Merges and splits: the composition section.
|
|
310
|
+
break;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
return rows.length > 0
|
|
314
|
+
? section(tr.t('detail.changes'), rows.length, table(rows, 'attrs changes'))
|
|
315
|
+
: null;
|
|
316
|
+
}
|
|
317
|
+
/** One attribute's change: lists as set changes, short values inline, long ones a line a side. */
|
|
318
|
+
#attrChange(nodeId, ch, tr) {
|
|
319
|
+
const beforeList = listItems(ch.before);
|
|
320
|
+
const afterList = listItems(ch.after);
|
|
321
|
+
if (beforeList && afterList) {
|
|
322
|
+
const b = new Set(beforeList);
|
|
323
|
+
const a = new Set(afterList);
|
|
324
|
+
return items(afterList.filter((x) => !b.has(x)), beforeList.filter((x) => !a.has(x)), tr, afterList.filter((x) => b.has(x)));
|
|
325
|
+
}
|
|
326
|
+
const key = `${nodeId}|${ch.key}`;
|
|
327
|
+
const before = formatValue(ch.before);
|
|
328
|
+
const after = formatValue(ch.after);
|
|
329
|
+
if (ch.before === undefined) {
|
|
330
|
+
const ins = h('ins', { class: 'hl', text: after });
|
|
331
|
+
return [signed('new', this.#value(`${key}|a`, after, tr, [ins]))];
|
|
332
|
+
}
|
|
333
|
+
if (ch.after === undefined) {
|
|
334
|
+
const del = h('del', { class: 'hl', text: before });
|
|
335
|
+
return [signed('old', this.#value(`${key}|b`, before, tr, [del]))];
|
|
336
|
+
}
|
|
337
|
+
const segs = typeof ch.before === 'string' && typeof ch.after === 'string'
|
|
338
|
+
? diffWords(before, after)
|
|
339
|
+
: [
|
|
340
|
+
{ op: 'delete', text: before },
|
|
341
|
+
{ op: 'insert', text: after },
|
|
342
|
+
];
|
|
343
|
+
const b = marked(segs, 'before');
|
|
344
|
+
const a = marked(segs, 'after');
|
|
345
|
+
return before.length + after.length <= INLINE_CHARS && !/\n/.test(before + after)
|
|
346
|
+
? [pair(b, a, tr)]
|
|
347
|
+
: [
|
|
348
|
+
signed('old', this.#value(`${key}|b`, before, tr, b)),
|
|
349
|
+
signed('new', this.#value(`${key}|a`, after, tr, a)),
|
|
350
|
+
];
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* Identity and attributes, without what the changes section shows. Folded, the attributes
|
|
354
|
+
* (all unchanged) hide behind a toggle; otherwise they get a section of their own.
|
|
355
|
+
*/
|
|
356
|
+
#overview(node, tr, showName, fold) {
|
|
357
|
+
const has = (kind) => node.facets.some((f) => f.kind === kind);
|
|
358
|
+
const current = node.after ?? node.before;
|
|
359
|
+
const rows = [];
|
|
360
|
+
if (showName && !has('rename'))
|
|
361
|
+
rows.push([tr.t('detail.name'), node.label]);
|
|
362
|
+
if (!has('rekey')) {
|
|
363
|
+
rows.push([
|
|
364
|
+
tr.t('detail.id'),
|
|
365
|
+
h('span', { class: 'id-text', text: node.afterId ?? node.beforeId ?? node.id }),
|
|
366
|
+
]);
|
|
367
|
+
}
|
|
368
|
+
if (!has('types') && node.types.length > 0) {
|
|
369
|
+
rows.push([tr.t('detail.types'), chips([], [], node.types)]);
|
|
370
|
+
}
|
|
371
|
+
if (!has('aliases') && current && current.aliases.length > 0) {
|
|
372
|
+
rows.push([tr.t('detail.aliases'), chips([], [], current.aliases)]);
|
|
373
|
+
}
|
|
374
|
+
const status = [tr.t(`status.${node.status}`)];
|
|
375
|
+
if (current?.deprecated && !has('deprecate'))
|
|
376
|
+
status.push(` · ${tr.t('detail.deprecated')}`);
|
|
377
|
+
if (current?.implicit)
|
|
378
|
+
status.push(` · ${tr.t('detail.implicit')}`);
|
|
379
|
+
rows.push([tr.t('detail.status'), status]);
|
|
380
|
+
const all = current?.attrs ?? {};
|
|
381
|
+
const changed = new Set();
|
|
382
|
+
for (const f of node.facets) {
|
|
383
|
+
if (f.kind === 'attrs')
|
|
384
|
+
for (const c of f.changes)
|
|
385
|
+
changed.add(c.key);
|
|
386
|
+
}
|
|
387
|
+
const keys = Object.keys(all)
|
|
388
|
+
.filter((k) => !changed.has(k))
|
|
389
|
+
.sort();
|
|
390
|
+
const attrs = () => table(keys.map((k) => [k, this.#value(`${node.id}|u|${k}`, formatValue(all[k]), tr)]));
|
|
391
|
+
if (!fold) {
|
|
392
|
+
const out = [section(tr.t('detail.identity'), null, kv(rows))];
|
|
393
|
+
if (keys.length > 0)
|
|
394
|
+
out.push(section(tr.t('detail.attributes'), null, attrs()));
|
|
395
|
+
return out;
|
|
396
|
+
}
|
|
397
|
+
return [
|
|
398
|
+
section(tr.t('detail.identity'), null, kv(rows), keys.length > 0
|
|
399
|
+
? h('button', {
|
|
400
|
+
type: 'button',
|
|
401
|
+
class: 'disclosure',
|
|
402
|
+
'data-focus-key': 'attrs-more',
|
|
403
|
+
'aria-expanded': String(this.#showUnchangedAttrs),
|
|
404
|
+
onclick: () => {
|
|
405
|
+
this.#showUnchangedAttrs = !this.#showUnchangedAttrs;
|
|
406
|
+
this.#render();
|
|
407
|
+
},
|
|
408
|
+
}, tr.plural('detail.unchangedAttrs', keys.length), icon('chevron-down'))
|
|
409
|
+
: null, keys.length > 0 && this.#showUnchangedAttrs ? attrs() : null),
|
|
410
|
+
];
|
|
411
|
+
}
|
|
412
|
+
/** A value cell, clamped to 4 lines with “Show more” when long. */
|
|
413
|
+
#value(key, text, tr, content) {
|
|
414
|
+
const long = text.length > CLAMP_CHARS;
|
|
415
|
+
const open = this.#expandedValues.has(key);
|
|
416
|
+
const v = h('div', { class: `val${long && !open ? ' clamped' : ''}` }, ...(content ?? [text]));
|
|
417
|
+
if (!long)
|
|
418
|
+
return v;
|
|
419
|
+
return h('div', null, v, h('button', {
|
|
420
|
+
type: 'button',
|
|
421
|
+
class: 'link-btn more',
|
|
422
|
+
'data-focus-key': `value:${key}`,
|
|
423
|
+
text: tr.t(open ? 'detail.showLess' : 'detail.showMore'),
|
|
424
|
+
onclick: () => {
|
|
425
|
+
if (open)
|
|
426
|
+
this.#expandedValues.delete(key);
|
|
427
|
+
else
|
|
428
|
+
this.#expandedValues.add(key);
|
|
429
|
+
this.#render();
|
|
430
|
+
},
|
|
431
|
+
}));
|
|
432
|
+
}
|
|
433
|
+
#composition(node, diff, tr, label) {
|
|
434
|
+
const rows = [];
|
|
435
|
+
const via = (v, confidence) => v === 'hint'
|
|
436
|
+
? tr.t('detail.viaHint')
|
|
437
|
+
: `${tr.t('detail.viaHeuristic')} · ${tr.t('detail.confidence', { p: formatPercent(confidence) })}`;
|
|
438
|
+
for (const f of node.facets) {
|
|
439
|
+
switch (f.kind) {
|
|
440
|
+
case 'mergedInto':
|
|
441
|
+
rows.push(h('div', { class: 'comp-row' }, chip(node.label, 'del'), h('span', { class: 'arrow', 'aria-hidden': 'true', text: '→' }), chip(label(f.target), 'same'), h('span', { class: 'note', text: via(f.via, f.confidence) })));
|
|
442
|
+
break;
|
|
443
|
+
case 'mergeTarget': {
|
|
444
|
+
const notes = f.sources.map((s) => {
|
|
445
|
+
const src = diff.index.node(s);
|
|
446
|
+
const m = src?.facets.find((x) => x.kind === 'mergedInto');
|
|
447
|
+
return m && m.kind === 'mergedInto' ? via(m.via, m.confidence) : '';
|
|
448
|
+
});
|
|
449
|
+
rows.push(h('div', { class: 'comp-row' }, h('span', { class: 'note', text: tr.t('detail.mergedFrom') })));
|
|
450
|
+
f.sources.forEach((s, i) => {
|
|
451
|
+
rows.push(h('div', { class: 'comp-row' }, chip(label(s), 'del'), h('span', { class: 'arrow', 'aria-hidden': 'true', text: '→' }), chip(node.label, 'same'), notes[i] ? h('span', { class: 'note', text: notes[i] }) : null));
|
|
452
|
+
});
|
|
453
|
+
break;
|
|
454
|
+
}
|
|
455
|
+
case 'splitFrom':
|
|
456
|
+
rows.push(h('div', { class: 'comp-row' }, chip(label(f.source), 'same'), h('span', { class: 'arrow', 'aria-hidden': 'true', text: '→' }), chip(node.label, 'add'), h('span', { class: 'note', text: via(f.via, f.confidence) })));
|
|
457
|
+
break;
|
|
458
|
+
case 'splitInto':
|
|
459
|
+
rows.push(h('div', { class: 'comp-row' }, h('span', { class: 'note', text: tr.t('detail.splitInto') })), h('div', { class: 'comp-row' }, chip(node.label, 'same'), h('span', { class: 'arrow', 'aria-hidden': 'true', text: '→' }), f.targets.map((t) => chip(label(t), 'add'))));
|
|
460
|
+
break;
|
|
461
|
+
default:
|
|
462
|
+
break;
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
return rows.length
|
|
466
|
+
? section(tr.t('detail.composition'), null, h('div', { class: 'comp' }, rows))
|
|
467
|
+
: null;
|
|
468
|
+
}
|
|
469
|
+
#evidence(node, diff, tr, label) {
|
|
470
|
+
const parts = [];
|
|
471
|
+
const rekey = node.facets.find((f) => f.kind === 'rekey');
|
|
472
|
+
if (rekey && node.afterId !== undefined) {
|
|
473
|
+
const m = diff.matches.find((x) => x.after === node.afterId);
|
|
474
|
+
if (m?.method === 'hint')
|
|
475
|
+
parts.push(h('div', { class: 'note-line', text: tr.t('detail.matchHint') }));
|
|
476
|
+
else if (m) {
|
|
477
|
+
parts.push(h('div', {
|
|
478
|
+
class: 'note-line',
|
|
479
|
+
text: tr.t('detail.matchScore', { p: formatPercent(m.score) }),
|
|
480
|
+
}));
|
|
481
|
+
if (m.evidence)
|
|
482
|
+
parts.push(this.#bars(m.evidence, tr));
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
const suggestions = diff.suggestions.filter((s) => (node.beforeId !== undefined && node.status === 'removed' && s.before === node.beforeId) ||
|
|
486
|
+
(node.afterId !== undefined && node.status === 'added' && s.after === node.afterId));
|
|
487
|
+
for (const s of suggestions) {
|
|
488
|
+
const other = node.status === 'removed'
|
|
489
|
+
? diff.index.nodeByAfter(s.after)
|
|
490
|
+
: diff.index.nodeByBefore(s.before);
|
|
491
|
+
parts.push(h('div', { class: 'comp-row', style: 'margin-top: 8px' }, h('span', { class: 'note', text: tr.t('detail.suggestion') }), chip(other ? label(other.id) : node.status === 'removed' ? s.after : s.before, 'same'), h('span', {
|
|
492
|
+
class: 'note',
|
|
493
|
+
text: `${tr.t('detail.matchScore', { p: formatPercent(s.score) })} · ${tr.t(s.reason === 'ambiguous' ? 'detail.suggestion.ambiguous' : 'detail.suggestion.below')}`,
|
|
494
|
+
})), this.#bars(s.evidence, tr));
|
|
495
|
+
}
|
|
496
|
+
return parts.length ? section(tr.t('detail.evidence'), null, ...parts) : null;
|
|
497
|
+
}
|
|
498
|
+
#bars(e, tr) {
|
|
499
|
+
const rows = [
|
|
500
|
+
[tr.t('detail.evidence.label'), e.label],
|
|
501
|
+
[tr.t('detail.evidence.neighbors'), e.neighbors],
|
|
502
|
+
[tr.t('detail.evidence.types'), e.types],
|
|
503
|
+
[tr.t('detail.evidence.attrs'), e.attrs],
|
|
504
|
+
];
|
|
505
|
+
return h('div', { class: 'bars', style: 'margin-top: 8px' }, rows.map(([k, v]) => h('div', { class: 'bar-row' }, h('span', { class: 'lbl', text: k }), h('span', {
|
|
506
|
+
class: 'track',
|
|
507
|
+
role: 'meter',
|
|
508
|
+
'aria-label': k,
|
|
509
|
+
'aria-valuemin': '0',
|
|
510
|
+
'aria-valuemax': '100',
|
|
511
|
+
'aria-valuenow': String(Math.round(v * 100)),
|
|
512
|
+
}, h('span', {
|
|
513
|
+
class: 'fill',
|
|
514
|
+
style: `display:block; width: ${Math.round(Math.max(0, Math.min(1, v)) * 100)}%`,
|
|
515
|
+
})), h('span', { class: 'v', text: formatPercent(v) }))));
|
|
516
|
+
}
|
|
517
|
+
// ─── Relations ───────────────────────────────────────────────────────────
|
|
518
|
+
#relations(edges, focusId, scene, diff, tr, changed) {
|
|
519
|
+
const sorted = changed
|
|
520
|
+
? edges
|
|
521
|
+
: [...edges].sort((a, b) => Number(a.source !== focusId) - Number(b.source !== focusId));
|
|
522
|
+
const shown = this.#showAllRelations ? sorted : sorted.slice(0, MAX_RELATIONS);
|
|
523
|
+
const list = h('div', { class: 'rels' });
|
|
524
|
+
for (const e of shown)
|
|
525
|
+
list.appendChild(this.#relation(e, focusId, scene, diff, tr));
|
|
526
|
+
const rest = sorted.length - shown.length;
|
|
527
|
+
return section(tr.t('detail.relations'), edges.length, list, rest > 0 || this.#showAllRelations
|
|
528
|
+
? h('button', {
|
|
529
|
+
type: 'button',
|
|
530
|
+
class: 'disclosure',
|
|
531
|
+
'data-focus-key': 'rels-more',
|
|
532
|
+
'aria-expanded': String(this.#showAllRelations),
|
|
533
|
+
onclick: () => {
|
|
534
|
+
this.#showAllRelations = !this.#showAllRelations;
|
|
535
|
+
this.#render();
|
|
536
|
+
},
|
|
537
|
+
}, this.#showAllRelations
|
|
538
|
+
? tr.t('detail.showLess')
|
|
539
|
+
: tr.plural('detail.moreRelations', rest), icon('chevron-down'))
|
|
540
|
+
: null);
|
|
541
|
+
}
|
|
542
|
+
#relation(e, focusId, scene, diff, tr) {
|
|
543
|
+
const c = this.#ctx.controller;
|
|
544
|
+
const label = (id) => diff.index.node(id)?.label ?? id;
|
|
545
|
+
const node = (id) => h('span', { class: 'node', text: label(id) });
|
|
546
|
+
const was = (id) => h('span', { class: 'was', text: ` (${tr.t('detail.was', { x: tr.quote(label(id)) })})` });
|
|
547
|
+
const retarget = e.facets.find((f) => f.kind === 'retarget');
|
|
548
|
+
const predicate = e.facets.find((f) => f.kind === 'predicate');
|
|
549
|
+
const relabel = e.facets.find((f) => f.kind === 'label');
|
|
550
|
+
const pred = h('span', { class: 'pred', text: ` —${e.label}→ ` });
|
|
551
|
+
const outgoing = focusId !== undefined && e.source === focusId && e.target !== focusId;
|
|
552
|
+
const incoming = focusId !== undefined && e.target === focusId && e.source !== focusId;
|
|
553
|
+
const s = [];
|
|
554
|
+
if (outgoing) {
|
|
555
|
+
s.push(h('span', { class: 'pred', text: `→ ${e.label} → ` }), node(e.target));
|
|
556
|
+
if (retarget?.end === 'target')
|
|
557
|
+
s.push(was(retarget.from));
|
|
558
|
+
}
|
|
559
|
+
else if (incoming) {
|
|
560
|
+
s.push(h('span', { class: 'pred', text: `← ${e.label} ← ` }), node(e.source));
|
|
561
|
+
if (retarget?.end === 'source')
|
|
562
|
+
s.push(was(retarget.from));
|
|
563
|
+
}
|
|
564
|
+
else {
|
|
565
|
+
s.push(node(e.source));
|
|
566
|
+
if (retarget?.end === 'source')
|
|
567
|
+
s.push(was(retarget.from));
|
|
568
|
+
s.push(pred, node(e.target));
|
|
569
|
+
if (retarget?.end === 'target')
|
|
570
|
+
s.push(was(retarget.from));
|
|
571
|
+
}
|
|
572
|
+
const prevLabel = predicate
|
|
573
|
+
? (e.before?.label ?? predicate.from)
|
|
574
|
+
: relabel
|
|
575
|
+
? relabel.from
|
|
576
|
+
: undefined;
|
|
577
|
+
if (prevLabel !== undefined) {
|
|
578
|
+
s.push(h('span', { class: 'was', text: ` (${tr.t('detail.was', { x: tr.quote(prevLabel) })})` }));
|
|
579
|
+
}
|
|
580
|
+
if (e.facets.some((f) => f.kind === 'attrs')) {
|
|
581
|
+
s.push(h('span', { class: 'was', text: ` · ${tr.t('detail.edgeAttrs')}` }));
|
|
582
|
+
}
|
|
583
|
+
if (e.facets.some((f) => f.kind === 'collapsed')) {
|
|
584
|
+
s.push(h('span', { class: 'was', text: ` · ${tr.t('detail.collapsed')}` }));
|
|
585
|
+
}
|
|
586
|
+
const sign = e.status === 'added'
|
|
587
|
+
? '+'
|
|
588
|
+
: e.status === 'removed'
|
|
589
|
+
? '−'
|
|
590
|
+
: e.status === 'modified'
|
|
591
|
+
? '~'
|
|
592
|
+
: '·';
|
|
593
|
+
const j = scene.edgeIndex.get(e.id);
|
|
594
|
+
const family = familyOfEdge(e);
|
|
595
|
+
return h('button', {
|
|
596
|
+
type: 'button',
|
|
597
|
+
class: `rel ${e.status}`,
|
|
598
|
+
'data-focus-key': `rel:${e.id}`,
|
|
599
|
+
'data-family': family,
|
|
600
|
+
title: tr.t('detail.showOnCanvas'),
|
|
601
|
+
disabled: j === undefined,
|
|
602
|
+
onclick: () => {
|
|
603
|
+
if (j !== undefined)
|
|
604
|
+
c.pinEdge(j);
|
|
605
|
+
},
|
|
606
|
+
}, h('span', { class: 'sign', 'aria-hidden': 'true', text: sign }), h('span', { class: 's' }, ...s));
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
//# sourceMappingURL=detail.js.map
|