@glossarist/concept-browser 0.7.128 → 0.7.129

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glossarist/concept-browser",
3
- "version": "0.7.128",
3
+ "version": "0.7.129",
4
4
  "description": "Vue SPA for browsing Glossarist terminology datasets with cross-reference resolution, graph visualization, and multi-language support",
5
5
  "type": "module",
6
6
  "bin": {
@@ -0,0 +1,74 @@
1
+ import { describe, it, expect } from 'vitest';
2
+
3
+ /**
4
+ * Tests for citeResolver DATASET:ID matching logic.
5
+ *
6
+ * The citeResolver must parse {{cite:IEV:702-02-07}} and match it
7
+ * against sources that have:
8
+ * - id: "702-02-07" (the ID part)
9
+ * - origin.ref: { source: "IEV", id: "702-02-07" }
10
+ *
11
+ * Previously, it only matched s.id === key, so "IEV:702-02-07"
12
+ * never matched source.id "702-02-07".
13
+ */
14
+
15
+ interface SourceLike {
16
+ id: string | null;
17
+ origin?: {
18
+ ref?: { source?: string; id?: string } | null;
19
+ link?: string | null;
20
+ } | null;
21
+ }
22
+
23
+ function findSource(key: string, sources: SourceLike[]): SourceLike | undefined {
24
+ const lastColon = key.lastIndexOf(':');
25
+ const idPart = lastColon > 0 ? key.slice(lastColon + 1) : key;
26
+ const datasetPart = lastColon > 0 ? key.slice(0, lastColon) : '';
27
+
28
+ return sources.find(s => {
29
+ if (s.id === key || s.id === idPart) return true;
30
+ const ref = s.origin?.ref;
31
+ if (ref) {
32
+ if (datasetPart && ref.source === datasetPart && ref.id === idPart) return true;
33
+ if (ref.id === key || ref.id === idPart) return true;
34
+ }
35
+ return false;
36
+ });
37
+ }
38
+
39
+ describe('citeResolver DATASET:ID matching', () => {
40
+ const sources: SourceLike[] = [
41
+ { id: null, origin: { ref: { source: 'IEV', id: '845-01-01' }, link: 'https://electropedia.org/...' } },
42
+ { id: '845-01-01', origin: { ref: { source: 'IEV', id: '845-01-01' }, link: 'https://electropedia.org/...' } },
43
+ { id: '702-02-07', origin: { ref: { source: 'IEV', id: '702-02-07' }, link: 'https://electropedia.org/...' } },
44
+ { id: null, origin: { ref: { source: 'CIE S 017:2011', id: '17-370' } } },
45
+ ];
46
+
47
+ it('matches cite:IEV:845-01-01 via origin.ref', () => {
48
+ const s = findSource('IEV:845-01-01', sources);
49
+ expect(s).toBeDefined();
50
+ expect(s!.origin!.ref!.id).toBe('845-01-01');
51
+ });
52
+
53
+ it('matches cite:IEV:702-02-07 via source id', () => {
54
+ const s = findSource('IEV:702-02-07', sources);
55
+ expect(s).toBeDefined();
56
+ expect(s!.id).toBe('702-02-07');
57
+ });
58
+
59
+ it('matches cite:845-01-01 (bare ID without dataset prefix)', () => {
60
+ const s = findSource('845-01-01', sources);
61
+ expect(s).toBeDefined();
62
+ });
63
+
64
+ it('matches cite with CIE dataset prefix', () => {
65
+ const s = findSource('CIE S 017:2011:17-370', sources);
66
+ expect(s).toBeDefined();
67
+ expect(s!.origin!.ref!.id).toBe('17-370');
68
+ });
69
+
70
+ it('returns undefined for unknown source', () => {
71
+ const s = findSource('UNKNOWN:999', sources);
72
+ expect(s).toBeUndefined();
73
+ });
74
+ });
@@ -65,7 +65,24 @@ export function useRenderOptions(
65
65
  return `<span class="cite-ref">${escapeHtml(label ?? key)}</span>`;
66
66
  }
67
67
 
68
- const source = sources.find(s => s.id === key);
68
+ // Parse DATASET:ID format. {{cite:IEV:702-02-07}} → dataset="IEV", idPart="702-02-07"
69
+ // Match against: raw id, id part, or origin.ref { source: dataset, id: idPart }
70
+ const lastColon = key.lastIndexOf(':');
71
+ const idPart = lastColon > 0 ? key.slice(lastColon + 1) : key;
72
+ const datasetPart = lastColon > 0 ? key.slice(0, lastColon) : '';
73
+
74
+ const source = sources.find(s => {
75
+ // Match by source id (raw or id part)
76
+ if (s.id === key || s.id === idPart) return true;
77
+ // Match by origin.ref
78
+ const ref = s.origin?.ref;
79
+ if (ref) {
80
+ if (datasetPart && ref.source === datasetPart && ref.id === idPart) return true;
81
+ if (ref.id === key || ref.id === idPart) return true;
82
+ }
83
+ return false;
84
+ });
85
+
69
86
  if (!source?.origin) {
70
87
  return `<span class="cite-unresolved">${escapeHtml(label ?? key)}</span>`;
71
88
  }