repometry 0.4.1 → 0.5.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/README.md +4 -0
- package/package.json +1 -1
- package/target/main/resources/report/json/report-v2.schema.json +13 -1
- package/target/main/resources/viewer/files.css +7 -3
- package/target/main/resources/viewer/styles.css +2 -2
- package/target/main/ts/api/git/git.d.ts +1 -0
- package/target/main/ts/api/git/git.js +12 -0
- package/target/main/ts/api/git/inspection-source.js +2 -8
- package/target/main/ts/api/git/local.d.ts +1 -1
- package/target/main/ts/api/git/local.js +39 -5
- package/target/main/ts/api/process/docker-tool-runner.d.ts +13 -0
- package/target/main/ts/api/process/docker-tool-runner.js +108 -0
- package/target/main/ts/api/process/failure.d.ts +1 -0
- package/target/main/ts/api/process/failure.js +12 -0
- package/target/main/ts/api/process/plugin.d.ts +10 -0
- package/target/main/ts/api/process/plugin.js +96 -0
- package/target/main/ts/compose/analyze-snapshot.d.ts +3 -2
- package/target/main/ts/compose/analyze-snapshot.js +82 -29
- package/target/main/ts/compose/inspect.d.ts +5 -0
- package/target/main/ts/compose/inspect.js +10 -6
- package/target/main/ts/core/engine/execute.d.ts +3 -1
- package/target/main/ts/core/engine/execute.js +14 -2
- package/target/main/ts/core/engine/operation-cache.d.ts +14 -0
- package/target/main/ts/core/engine/operation-cache.js +66 -0
- package/target/main/ts/core/engine/plan.d.ts +1 -0
- package/target/main/ts/core/engine/plan.js +22 -3
- package/target/main/ts/core/engine/plugin.d.ts +8 -1
- package/target/main/ts/core/engine/plugin.js +1 -3
- package/target/main/ts/core/engine/report-products.js +2 -13
- package/target/main/ts/core/model/clone-source.js +1 -1
- package/target/main/ts/core/model/code-structure.d.ts +3 -0
- package/target/main/ts/core/model/code-structure.js +4 -1
- package/target/main/ts/core/model/finding-ignore.js +1 -1
- package/target/main/ts/core/model/finding.js +1 -1
- package/target/main/ts/core/model/line-coverage.d.ts +5 -1
- package/target/main/ts/core/model/line-coverage.js +14 -11
- package/target/main/ts/core/model/measurement.js +1 -1
- package/target/main/ts/core/model/plugin-data.d.ts +2 -0
- package/target/main/ts/core/model/plugin-data.js +15 -1
- package/target/main/ts/core/model/quality-summary.js +1 -1
- package/target/main/ts/core/model/scanner-import.js +1 -1
- package/target/main/ts/core/model/snapshot.d.ts +1 -0
- package/target/main/ts/core/model/snapshot.js +5 -1
- package/target/main/ts/core/model/source.d.ts +3 -0
- package/target/main/ts/core/model/source.js +15 -0
- package/target/main/ts/core/ports/tool-runner.d.ts +18 -0
- package/target/main/ts/core/ports/tool-runner.js +2 -0
- package/target/main/ts/plugin.d.ts +7 -1
- package/target/main/ts/plugin.js +3 -1
- package/target/main/ts/plugins/coverage/coverage.d.ts +5 -2
- package/target/main/ts/plugins/coverage/coverage.js +35 -10
- package/target/main/ts/plugins/language-js/function-facts.d.ts +1 -0
- package/target/main/ts/plugins/language-js/function-facts.js +30 -4
- package/target/main/ts/report/html/app/viewer-chart-bars.d.ts +11 -0
- package/target/main/ts/report/html/app/viewer-chart-bars.js +54 -0
- package/target/main/ts/report/html/app/viewer-chart-label.d.ts +15 -0
- package/target/main/ts/report/html/app/viewer-chart-label.js +43 -0
- package/target/main/ts/report/html/app/viewer-chart-line.d.ts +24 -0
- package/target/main/ts/report/html/app/viewer-chart-line.js +89 -0
- package/target/main/ts/report/html/app/viewer-chart-points.d.ts +49 -0
- package/target/main/ts/report/html/app/viewer-chart-points.js +74 -0
- package/target/main/ts/report/html/app/viewer-chart-scale.d.ts +21 -0
- package/target/main/ts/report/html/app/viewer-chart-scale.js +93 -0
- package/target/main/ts/report/html/app/viewer-chart-svg.d.ts +28 -0
- package/target/main/ts/report/html/app/viewer-chart-svg.js +41 -0
- package/target/main/ts/report/html/app/viewer-chart-time.d.ts +26 -0
- package/target/main/ts/report/html/app/viewer-chart-time.js +150 -0
- package/target/main/ts/report/html/app/viewer-chart-tip.d.ts +4 -0
- package/target/main/ts/report/html/app/viewer-chart-tip.js +210 -0
- package/target/main/ts/report/html/app/viewer-chart-x.d.ts +12 -0
- package/target/main/ts/report/html/app/viewer-chart-x.js +50 -0
- package/target/main/ts/report/html/app/viewer-chart.d.ts +4 -98
- package/target/main/ts/report/html/app/viewer-chart.js +16 -677
- package/target/main/ts/report/html/app/viewer-code-map.d.ts +27 -0
- package/target/main/ts/report/html/app/viewer-code-map.js +175 -0
- package/target/main/ts/report/html/app/viewer-columns.d.ts +38 -0
- package/target/main/ts/report/html/app/viewer-columns.js +92 -0
- package/target/main/ts/report/html/app/viewer-commit-picker.d.ts +12 -0
- package/target/main/ts/report/html/app/viewer-commit-picker.js +229 -0
- package/target/main/ts/report/html/app/viewer-commits.d.ts +5 -9
- package/target/main/ts/report/html/app/viewer-commits.js +17 -216
- package/target/main/ts/report/html/app/viewer-controls.d.ts +43 -0
- package/target/main/ts/report/html/app/viewer-controls.js +141 -0
- package/target/main/ts/report/html/app/viewer-copy.d.ts +17 -0
- package/target/main/ts/report/html/app/viewer-copy.js +64 -0
- package/target/main/ts/report/html/app/viewer-diagnostics.d.ts +4 -0
- package/target/main/ts/report/html/app/viewer-diagnostics.js +60 -0
- package/target/main/ts/report/html/app/viewer-dom.d.ts +27 -0
- package/target/main/ts/report/html/app/viewer-dom.js +99 -0
- package/target/main/ts/report/html/app/viewer-file-aside.d.ts +19 -0
- package/target/main/ts/report/html/app/viewer-file-aside.js +124 -0
- package/target/main/ts/report/html/app/viewer-file-figures.d.ts +15 -0
- package/target/main/ts/report/html/app/viewer-file-figures.js +60 -0
- package/target/main/ts/report/html/app/viewer-file-source.d.ts +7 -0
- package/target/main/ts/report/html/app/viewer-file-source.js +119 -0
- package/target/main/ts/report/html/app/viewer-files.d.ts +2 -118
- package/target/main/ts/report/html/app/viewer-files.js +24 -2184
- package/target/main/ts/report/html/app/viewer-filter.d.ts +3 -51
- package/target/main/ts/report/html/app/viewer-filter.js +111 -450
- package/target/main/ts/report/html/app/viewer-hotspots.d.ts +4 -0
- package/target/main/ts/report/html/app/viewer-hotspots.js +131 -0
- package/target/main/ts/report/html/app/viewer-inspection.d.ts +69 -0
- package/target/main/ts/report/html/app/viewer-inspection.js +36 -0
- package/target/main/ts/report/html/app/viewer-issue-group.d.ts +27 -0
- package/target/main/ts/report/html/app/viewer-issue-group.js +174 -0
- package/target/main/ts/report/html/app/viewer-issues.d.ts +4 -0
- package/target/main/ts/report/html/app/viewer-issues.js +173 -0
- package/target/main/ts/report/html/app/viewer-language-bar.d.ts +9 -0
- package/target/main/ts/report/html/app/viewer-language-bar.js +72 -0
- package/target/main/ts/report/html/app/viewer-languages.d.ts +27 -0
- package/target/main/ts/report/html/app/viewer-languages.js +93 -0
- package/target/main/ts/report/html/app/viewer-layout.d.ts +14 -0
- package/target/main/ts/report/html/app/viewer-layout.js +134 -0
- package/target/main/ts/report/html/app/viewer-line-coverage.d.ts +47 -0
- package/target/main/ts/report/html/app/viewer-line-coverage.js +121 -0
- package/target/main/ts/report/html/app/viewer-locations.d.ts +16 -0
- package/target/main/ts/report/html/app/viewer-locations.js +31 -0
- package/target/main/ts/report/html/app/viewer-map-scale.d.ts +26 -0
- package/target/main/ts/report/html/app/viewer-map-scale.js +147 -0
- package/target/main/ts/report/html/app/viewer-map-shape.d.ts +42 -0
- package/target/main/ts/report/html/app/viewer-map-shape.js +102 -0
- package/target/main/ts/report/html/app/viewer-metric-format.d.ts +23 -0
- package/target/main/ts/report/html/app/viewer-metric-format.js +93 -0
- package/target/main/ts/report/html/app/viewer-metric-registry.d.ts +0 -20
- package/target/main/ts/report/html/app/viewer-metric-registry.js +0 -77
- package/target/main/ts/report/html/app/viewer-metrics-view.d.ts +4 -0
- package/target/main/ts/report/html/app/viewer-metrics-view.js +162 -0
- package/target/main/ts/report/html/app/viewer-metrics.d.ts +6 -1
- package/target/main/ts/report/html/app/viewer-metrics.js +53 -35
- package/target/main/ts/report/html/app/viewer-overview-cards.d.ts +12 -0
- package/target/main/ts/report/html/app/viewer-overview-cards.js +112 -0
- package/target/main/ts/report/html/app/viewer-overview-hotspots.d.ts +9 -0
- package/target/main/ts/report/html/app/viewer-overview-hotspots.js +173 -0
- package/target/main/ts/report/html/app/viewer-overview-lead.d.ts +12 -0
- package/target/main/ts/report/html/app/viewer-overview-lead.js +116 -0
- package/target/main/ts/report/html/app/viewer-profile-badges.d.ts +11 -0
- package/target/main/ts/report/html/app/viewer-profile-badges.js +119 -0
- package/target/main/ts/report/html/app/viewer-profile-table.d.ts +29 -0
- package/target/main/ts/report/html/app/viewer-profile-table.js +124 -0
- package/target/main/ts/report/html/app/viewer-profile.d.ts +2 -6
- package/target/main/ts/report/html/app/viewer-profile.js +6 -248
- package/target/main/ts/report/html/app/viewer-pull-sections.d.ts +4 -0
- package/target/main/ts/report/html/app/viewer-pull-sections.js +118 -0
- package/target/main/ts/report/html/app/viewer-pull-trend.d.ts +5 -0
- package/target/main/ts/report/html/app/viewer-pull-trend.js +63 -0
- package/target/main/ts/report/html/app/viewer-pulls.d.ts +0 -1
- package/target/main/ts/report/html/app/viewer-pulls.js +28 -178
- package/target/main/ts/report/html/app/viewer-query-field.d.ts +19 -0
- package/target/main/ts/report/html/app/viewer-query-field.js +203 -0
- package/target/main/ts/report/html/app/viewer-route.d.ts +34 -0
- package/target/main/ts/report/html/app/viewer-route.js +55 -0
- package/target/main/ts/report/html/app/viewer-shell.d.ts +20 -0
- package/target/main/ts/report/html/app/viewer-shell.js +116 -0
- package/target/main/ts/report/html/app/viewer-source-view.d.ts +49 -0
- package/target/main/ts/report/html/app/viewer-source-view.js +150 -0
- package/target/main/ts/report/html/app/viewer-source.d.ts +0 -84
- package/target/main/ts/report/html/app/viewer-source.js +7 -363
- package/target/main/ts/report/html/app/viewer-suggest.d.ts +13 -0
- package/target/main/ts/report/html/app/viewer-suggest.js +91 -0
- package/target/main/ts/report/html/app/viewer-sunburst.d.ts +5 -0
- package/target/main/ts/report/html/app/viewer-sunburst.js +40 -0
- package/target/main/ts/report/html/app/viewer-table-cells.d.ts +25 -0
- package/target/main/ts/report/html/app/viewer-table-cells.js +129 -0
- package/target/main/ts/report/html/app/viewer-table-rows.d.ts +54 -0
- package/target/main/ts/report/html/app/viewer-table-rows.js +95 -0
- package/target/main/ts/report/html/app/viewer-tokenizer.d.ts +16 -0
- package/target/main/ts/report/html/app/viewer-tokenizer.js +192 -0
- package/target/main/ts/report/html/app/viewer-totals.d.ts +14 -0
- package/target/main/ts/report/html/app/viewer-totals.js +89 -0
- package/target/main/ts/report/html/app/viewer-treemap.d.ts +24 -0
- package/target/main/ts/report/html/app/viewer-treemap.js +112 -0
- package/target/main/ts/report/html/app/viewer-trend-data.d.ts +49 -0
- package/target/main/ts/report/html/app/viewer-trend-data.js +105 -0
- package/target/main/ts/report/html/app/viewer-trend-nav.d.ts +5 -0
- package/target/main/ts/report/html/app/viewer-trend-nav.js +85 -0
- package/target/main/ts/report/html/app/viewer-trend-points.d.ts +30 -0
- package/target/main/ts/report/html/app/viewer-trend-points.js +128 -0
- package/target/main/ts/report/html/app/viewer-trend-series.d.ts +26 -0
- package/target/main/ts/report/html/app/viewer-trend-series.js +98 -0
- package/target/main/ts/report/html/app/viewer-trends.d.ts +2 -70
- package/target/main/ts/report/html/app/viewer-trends.js +41 -392
- package/target/main/ts/report/html/app/viewer.js +152 -663
- package/target/main/ts/report/html/site/badges.js +41 -18
- package/target/main/ts/report/json/store/local-store.js +2 -12
- package/target/main/ts/report/json/store/operation-cache.d.ts +8 -0
- package/target/main/ts/report/json/store/operation-cache.js +32 -0
- package/target/main/ts/report/json/store/replace-file.d.ts +1 -0
- package/target/main/ts/report/json/store/replace-file.js +14 -0
- package/target/main/ts/report.d.ts +1 -0
- package/target/main/ts/report.js +1 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { InspectionDetails } from '../../json/wire/inspection-details-model.js';
|
|
2
|
+
import type { HotspotMetric } from './viewer-inspection.js';
|
|
3
|
+
import type { MapShape } from './viewer-map-shape.js';
|
|
4
|
+
export interface SunburstOptions {
|
|
5
|
+
readonly metric: HotspotMetric;
|
|
6
|
+
readonly directory?: string;
|
|
7
|
+
readonly compact?: boolean;
|
|
8
|
+
/** Rings (a sunburst) or tiles (a treemap); the last choice is remembered for this viewer. */
|
|
9
|
+
readonly shape?: MapShape;
|
|
10
|
+
/** Offered beside the map's title, where the page lets the viewer switch shapes. */
|
|
11
|
+
readonly reshape?: (shape: MapShape) => void;
|
|
12
|
+
/** More controls for the map's title row, such as what it is coloured by. */
|
|
13
|
+
readonly controls?: HTMLElement;
|
|
14
|
+
/** Sizes only, in grey: the map stands for an area with no measurement of its own, as security without a scanner. */
|
|
15
|
+
readonly muted?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Security: each file's worst finding level, 0 none to 4 critical, coloured in the grade steps of the security mark.
|
|
18
|
+
* A folder takes the worst level inside it. Files missing from the map have no findings.
|
|
19
|
+
*/
|
|
20
|
+
readonly levels?: ReadonlyMap<string, number>;
|
|
21
|
+
href(view: 'hotspots' | 'metrics', options?: {
|
|
22
|
+
directory?: string;
|
|
23
|
+
file?: string;
|
|
24
|
+
}): string;
|
|
25
|
+
}
|
|
26
|
+
/** The code map of a folder: its files sized by lines and coloured by the metric, as rings or tiles. */
|
|
27
|
+
export declare function renderSunburst(details: InspectionDetails, options: SunburstOptions): HTMLElement;
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { collator, count, element, inside, parentPath, svgElement } from './viewer-dom.js';
|
|
2
|
+
import { coverageText, duplicationText, hotspotScore } from './viewer-file-figures.js';
|
|
3
|
+
import { band, bandLimits, levelLegend, meaningOf, palette, relativePeaks, scoreLabel, spreadLevels, sunburstLegend } from './viewer-map-scale.js';
|
|
4
|
+
import { fullCircle, mapShape, readout, shapeSwitch, startAngle } from './viewer-map-shape.js';
|
|
5
|
+
import { securityRisks } from './viewer-metrics.js';
|
|
6
|
+
import { centerLabel, drawRings } from './viewer-sunburst.js';
|
|
7
|
+
import { unreadFolders } from './viewer-totals.js';
|
|
8
|
+
import { drawTiles } from './viewer-treemap.js';
|
|
9
|
+
/** The files and folders under the map's folder, by parent, sized by code lines where the folder has them. */
|
|
10
|
+
function mapTree(metrics, directory, metric, useCodeLines, levels) {
|
|
11
|
+
const byParent = new Map();
|
|
12
|
+
let measured = levels !== undefined;
|
|
13
|
+
const add = (entry, folder) => {
|
|
14
|
+
const area = useCodeLines ? entry.quality?.codeLines : entry.lines;
|
|
15
|
+
if (!area || !inside(entry.path, directory))
|
|
16
|
+
return;
|
|
17
|
+
const value = hotspotScore(entry, metric);
|
|
18
|
+
measured ||= value !== null;
|
|
19
|
+
// Nothing measured is nothing to count: a file without functions has no complexity, not an unknown one.
|
|
20
|
+
const branch = { entry, folder, area, score: levels ? levels.get(entry.path) ?? 0 : value ?? 0 };
|
|
21
|
+
const parent = parentPath(entry.path);
|
|
22
|
+
const siblings = byParent.get(parent);
|
|
23
|
+
if (siblings)
|
|
24
|
+
siblings.push(branch);
|
|
25
|
+
else
|
|
26
|
+
byParent.set(parent, [branch]);
|
|
27
|
+
};
|
|
28
|
+
for (const folder of metrics.directories)
|
|
29
|
+
if (folder.path)
|
|
30
|
+
add(folder, true);
|
|
31
|
+
for (const file of metrics.files)
|
|
32
|
+
add(file, false);
|
|
33
|
+
for (const group of byParent.values())
|
|
34
|
+
group.sort((a, b) => collator.compare(a.entry.path, b.entry.path));
|
|
35
|
+
return { byParent, measured };
|
|
36
|
+
}
|
|
37
|
+
/** How many levels the tree has below the map's folder. */
|
|
38
|
+
function treeDepth(byParent, directory) {
|
|
39
|
+
const base = directory ? directory.split('/').length : 0;
|
|
40
|
+
let depth = 1;
|
|
41
|
+
for (const group of byParent.values())
|
|
42
|
+
for (const branch of group)
|
|
43
|
+
depth = Math.max(depth, branch.entry.path.split('/').length - base);
|
|
44
|
+
return depth;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* How each place is shaded: security by its level, anything else by its band. A file no plugin read, or a folder of
|
|
48
|
+
* nothing else, has no measure: grey. Scanners read every file, so the security map colours them all.
|
|
49
|
+
*/
|
|
50
|
+
function shading(metrics, tree, metric, limits, levels) {
|
|
51
|
+
if (levels)
|
|
52
|
+
return branch => branch.score;
|
|
53
|
+
const unread = unreadFolders(metrics.files);
|
|
54
|
+
const peakOf = relativePeaks([...tree.byParent.values()].flat().map(branch => ({ path: branch.entry.path, folder: branch.folder, score: branch.score })));
|
|
55
|
+
return branch => branch.entry.analysed === false || unread.has(branch.entry.path) ? 'none'
|
|
56
|
+
: band(branch.entry, metric, branch.score, peakOf(branch.entry.path, branch.folder), limits);
|
|
57
|
+
}
|
|
58
|
+
/** The scale runs the panel's width under the title row: the key to the whole map. */
|
|
59
|
+
function mapLegend(metric, limits, levels, grey) {
|
|
60
|
+
if (grey)
|
|
61
|
+
return element('p', 'fx-note', 'Nothing measured for this map, so it shows sizes only.');
|
|
62
|
+
return levels ? levelLegend() : sunburstLegend(metric, limits);
|
|
63
|
+
}
|
|
64
|
+
const canvasSizes = {
|
|
65
|
+
rings: { compact: [400, 400], full: [400, 400] },
|
|
66
|
+
tiles: { compact: [400, 320], full: [640, 420] },
|
|
67
|
+
};
|
|
68
|
+
/** What a place's readout adds to its score: the share the ranking counts. */
|
|
69
|
+
function readingContext(metric, entry) {
|
|
70
|
+
if (metric === 'missedLines')
|
|
71
|
+
return ` · ${coverageText(entry)} covered`;
|
|
72
|
+
return metric === 'duplication' ? ` · ${duplicationText(entry)} duplicated` : '';
|
|
73
|
+
}
|
|
74
|
+
function mapHeading(options, shape) {
|
|
75
|
+
const heading = element('div', 'fx-map-heading');
|
|
76
|
+
if (options.reshape)
|
|
77
|
+
heading.append(shapeSwitch(shape, options.reshape));
|
|
78
|
+
if (options.controls)
|
|
79
|
+
heading.append(options.controls);
|
|
80
|
+
return heading;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* The map's panel. The view kind heads the map, at the left; what it is coloured by sits at the right. A title would
|
|
84
|
+
* only repeat what the switch and the map already say, so the panel is named for screen readers alone. The compact map
|
|
85
|
+
* has no title of its own: the switch alone heads it.
|
|
86
|
+
*/
|
|
87
|
+
function mapPanel(options, shape, compact) {
|
|
88
|
+
const panel = element('section', compact ? 'fx-sunburst fx-sunburst-compact' : 'panel fx-sunburst');
|
|
89
|
+
panel.dataset.shape = shape;
|
|
90
|
+
if (!compact)
|
|
91
|
+
panel.setAttribute('aria-label', 'Code map');
|
|
92
|
+
const heading = mapHeading(options, shape);
|
|
93
|
+
if (heading.childElementCount)
|
|
94
|
+
panel.append(heading);
|
|
95
|
+
return panel;
|
|
96
|
+
}
|
|
97
|
+
function mapCanvas(shape, compact, label) {
|
|
98
|
+
const canvas = svgElement('svg');
|
|
99
|
+
canvas.classList.add('fx-sunburst-chart');
|
|
100
|
+
const [width, height] = canvasSizes[shape][compact ? 'compact' : 'full'];
|
|
101
|
+
canvas.setAttribute('viewBox', `0 0 ${width} ${height}`);
|
|
102
|
+
if (shape === 'tiles')
|
|
103
|
+
canvas.classList.add('fx-treemap');
|
|
104
|
+
canvas.setAttribute('role', 'group');
|
|
105
|
+
canvas.setAttribute('aria-label', label);
|
|
106
|
+
return { canvas, width, height };
|
|
107
|
+
}
|
|
108
|
+
/** What the layouts draw with: each place a link to its folder's map or its file, named with its size and reading. */
|
|
109
|
+
function mapDraw(tree, depth, wedges) {
|
|
110
|
+
let drawn = 0;
|
|
111
|
+
return {
|
|
112
|
+
byParent: tree.byParent, depth, shade: wedges.shade,
|
|
113
|
+
get drawn() { return drawn; },
|
|
114
|
+
tile(branch, outline) {
|
|
115
|
+
drawn++;
|
|
116
|
+
const path = branch.entry.path;
|
|
117
|
+
const tile = svgElement('a');
|
|
118
|
+
tile.classList.add('fx-wedge');
|
|
119
|
+
tile.setAttribute('href', branch.folder ? wedges.href('hotspots', { directory: path })
|
|
120
|
+
: wedges.href('metrics', { directory: parentPath(path), file: path }));
|
|
121
|
+
tile.setAttribute('aria-label', `${path} · ${count(branch.area)} ${wedges.units} · ${wedges.reading(branch)}`);
|
|
122
|
+
tile.dataset.path = path;
|
|
123
|
+
const area = svgElement('path');
|
|
124
|
+
area.setAttribute('d', outline);
|
|
125
|
+
area.setAttribute('data-band', String(wedges.shade(branch)));
|
|
126
|
+
tile.append(area);
|
|
127
|
+
tile.addEventListener('focus', () => wedges.inspect(branch, tile));
|
|
128
|
+
tile.addEventListener('pointerenter', () => wedges.inspect(branch, tile));
|
|
129
|
+
wedges.canvas.append(tile);
|
|
130
|
+
return tile;
|
|
131
|
+
},
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
/** The code map of a folder: its files sized by lines and coloured by the metric, as rings or tiles. */
|
|
135
|
+
export function renderSunburst(details, options) {
|
|
136
|
+
const { metrics } = details;
|
|
137
|
+
const { metric, directory = '', compact = false } = options;
|
|
138
|
+
const limits = bandLimits(details, metric);
|
|
139
|
+
const shape = options.shape ?? mapShape();
|
|
140
|
+
const panel = mapPanel(options, shape, compact);
|
|
141
|
+
const useCodeLines = metrics.directories.find(entry => entry.path === directory)?.quality?.codeLines !== undefined;
|
|
142
|
+
const levels = options.levels && spreadLevels(options.levels);
|
|
143
|
+
const tree = mapTree(metrics, directory, metric, useCodeLines, levels);
|
|
144
|
+
const root = tree.byParent.get(directory);
|
|
145
|
+
if (!root?.length) {
|
|
146
|
+
panel.append(element('p', 'fx-note', 'No measured lines to show for this folder.'));
|
|
147
|
+
return panel;
|
|
148
|
+
}
|
|
149
|
+
const units = useCodeLines ? 'code lines' : 'physical lines';
|
|
150
|
+
const security = levels !== undefined;
|
|
151
|
+
// Grey marks no data: a metric this inspection did not measure at all (no coverage report) is not a map of zeros.
|
|
152
|
+
const grey = options.muted === true || !tree.measured;
|
|
153
|
+
panel.dataset.palette = palette(metric, security, grey);
|
|
154
|
+
const reading = (branch) => security ? securityRisks[branch.score] : `${count(branch.score)} ${scoreLabel(metric)}`;
|
|
155
|
+
// What the map encodes is said to assistive technology; on screen the legend's scale carries it.
|
|
156
|
+
const meaning = security ? 'Colour shows the worst security finding.' : meaningOf(metric);
|
|
157
|
+
const description = `${shape === 'tiles' ? 'Tile' : 'Wedge'} size shows ${units}. ${meaning}`;
|
|
158
|
+
if (!compact)
|
|
159
|
+
panel.append(mapLegend(metric, limits, security, grey));
|
|
160
|
+
const { canvas, width, height } = mapCanvas(shape, compact, `Code map of ${directory || 'the repository root'}. ${description}`);
|
|
161
|
+
const summary = element('p', 'fx-map-summary fx-map-hint fx-map-hint-quiet');
|
|
162
|
+
const map = mapDraw(tree, Math.min(treeDepth(tree.byParent, directory), compact ? 4 : 5), {
|
|
163
|
+
canvas, units, reading, href: options.href, shade: shading(metrics, tree, metric, limits, security),
|
|
164
|
+
inspect: readout(canvas, summary, branch => reading(branch) + readingContext(metric, branch.entry)),
|
|
165
|
+
});
|
|
166
|
+
if (shape === 'tiles')
|
|
167
|
+
drawTiles(map, root, { x: 0, y: 0, w: width, h: height }, 0);
|
|
168
|
+
else
|
|
169
|
+
drawRings(map, root, startAngle, startAngle + fullCircle, 0);
|
|
170
|
+
// The compact map sits beside the scope line, which already states the total; tiles have no centre to hold it.
|
|
171
|
+
if (!compact && shape === 'rings')
|
|
172
|
+
canvas.append(centerLabel(root.reduce((sum, branch) => sum + branch.area, 0), units));
|
|
173
|
+
panel.append(canvas, summary);
|
|
174
|
+
return panel;
|
|
175
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { Directory, Metrics } from './viewer-inspection.js';
|
|
2
|
+
/** What a scope holds that decides which columns open by default. */
|
|
3
|
+
export interface ColumnScope {
|
|
4
|
+
readonly ignored: boolean;
|
|
5
|
+
readonly sized: boolean;
|
|
6
|
+
}
|
|
7
|
+
export interface MetricColumn {
|
|
8
|
+
readonly label: string;
|
|
9
|
+
value(entry: Metrics): string | number | null;
|
|
10
|
+
display(entry: Metrics): string;
|
|
11
|
+
available?(directory?: Directory): boolean;
|
|
12
|
+
/** On unless it says otherwise, given what the scope holds: files no plugin read, and whether every file has a size. */
|
|
13
|
+
defaultVisible?(directory: Directory | undefined, scope: ColumnScope): boolean;
|
|
14
|
+
/** The first click sorts this way: worst first. Repometry's own columns open descending. */
|
|
15
|
+
readonly ascending?: boolean;
|
|
16
|
+
}
|
|
17
|
+
export type Columns = readonly [MetricColumn, ...MetricColumn[]];
|
|
18
|
+
/**
|
|
19
|
+
* The table's columns. The other coverage kinds sit beside line coverage; every other registry metric follows
|
|
20
|
+
* Repometry's own columns, except the counts a ratio is made of, which read through the ratio as line coverage's do.
|
|
21
|
+
*/
|
|
22
|
+
export declare function tableColumns(): Columns;
|
|
23
|
+
export interface ColumnSettings {
|
|
24
|
+
sort: number;
|
|
25
|
+
ascending: boolean;
|
|
26
|
+
readonly columns: Map<number, boolean>;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* The Columns menu: a checkbox per column the scope can show, each remembered once changed. The path always shows;
|
|
30
|
+
* a sort by a column that is hidden falls back to it.
|
|
31
|
+
*/
|
|
32
|
+
export declare function columnMenu(columns: Columns, settings: ColumnSettings, scope: {
|
|
33
|
+
readonly totals: Directory;
|
|
34
|
+
readonly files: readonly Metrics[];
|
|
35
|
+
}, change: () => void): {
|
|
36
|
+
menu: HTMLDetailsElement;
|
|
37
|
+
isVisible: (index: number) => boolean;
|
|
38
|
+
};
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { dismissible } from './viewer-controls.js';
|
|
2
|
+
import { count, element } from './viewer-dom.js';
|
|
3
|
+
import { coverageRatio, coverageText, duplicationRatio, duplicationText, effortText } from './viewer-file-figures.js';
|
|
4
|
+
import { sized } from './viewer-languages.js';
|
|
5
|
+
import { coverageKinds, localValue, measured } from './viewer-inspection.js';
|
|
6
|
+
import { firstSortAscending, format } from './viewer-metric-format.js';
|
|
7
|
+
import { labelOf, pluginMetrics, size } from './viewer-metrics.js';
|
|
8
|
+
/** A column of counts, shown with a dash where the file has none. */
|
|
9
|
+
function counted(label, read, extra = {}) {
|
|
10
|
+
return { label, value: entry => read(entry) ?? null, display: entry => count(read(entry)), ...extra };
|
|
11
|
+
}
|
|
12
|
+
/** Offered where the folder's totals have this quality measure. */
|
|
13
|
+
function hasQuality(key) {
|
|
14
|
+
return directory => directory?.quality?.[key] !== undefined;
|
|
15
|
+
}
|
|
16
|
+
const hidden = () => false;
|
|
17
|
+
const builtinColumns = [
|
|
18
|
+
{ label: 'Path', value: entry => entry.path, display: entry => entry.path },
|
|
19
|
+
counted(labelOf('code-lines'), entry => entry.quality?.codeLines, { available: hasQuality('codeLines') }),
|
|
20
|
+
// Ignored files have physical lines only: where there are some and no sizes, the language bar weighs in physical
|
|
21
|
+
// lines, and this column shows the numbers behind it. With sizes, the Size column does.
|
|
22
|
+
counted(labelOf('lines'), entry => entry.lines, { defaultVisible: (directory, scope) => (scope.ignored && !scope.sized) || !hasQuality('codeLines')(directory) }),
|
|
23
|
+
{ label: 'Size', value: entry => entry.bytes ?? null, display: entry => size(entry.bytes),
|
|
24
|
+
available: directory => directory?.bytes !== undefined, defaultVisible: (_, scope) => scope.sized },
|
|
25
|
+
counted('Functions', entry => entry.functions, { defaultVisible: hidden }),
|
|
26
|
+
counted(labelOf('complexity'), entry => entry.complexity?.maximum),
|
|
27
|
+
counted(labelOf('cognitive'), entry => entry.quality?.cognitiveComplexity, { available: hasQuality('cognitiveComplexity') }),
|
|
28
|
+
{ label: labelOf('coverage'), value: coverageRatio, display: coverageText, available: directory => !directory || coverageRatio(directory) !== null },
|
|
29
|
+
{ label: 'Duplication', value: duplicationRatio, display: duplicationText, available: hasQuality('duplication') },
|
|
30
|
+
{ label: labelOf('effort'), value: entry => entry.quality?.maintainability?.effortMinutes ?? null,
|
|
31
|
+
display: entry => effortText(entry.quality?.maintainability?.effortMinutes), available: hasQuality('maintainability') },
|
|
32
|
+
counted('Git changes', entry => entry.quality?.churn, { available: hasQuality('churn'), defaultVisible: hidden }),
|
|
33
|
+
counted('Diagnostics', entry => entry.diagnosticCount, { defaultVisible: hidden }),
|
|
34
|
+
];
|
|
35
|
+
/** Registry metrics as Metrics columns, in the order the history lists them. */
|
|
36
|
+
function pluginColumns(specs) {
|
|
37
|
+
return specs.map(spec => ({
|
|
38
|
+
label: spec.short,
|
|
39
|
+
value: entry => localValue(entry, spec),
|
|
40
|
+
display: entry => format(spec, localValue(entry, spec)),
|
|
41
|
+
available: () => measured(spec.descriptor),
|
|
42
|
+
defaultVisible: () => spec.column,
|
|
43
|
+
ascending: firstSortAscending(spec),
|
|
44
|
+
}));
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* The table's columns. The other coverage kinds sit beside line coverage; every other registry metric follows
|
|
48
|
+
* Repometry's own columns, except the counts a ratio is made of, which read through the ratio as line coverage's do.
|
|
49
|
+
*/
|
|
50
|
+
export function tableColumns() {
|
|
51
|
+
const kinds = coverageKinds();
|
|
52
|
+
const afterCoverage = builtinColumns.findIndex(column => column.label === labelOf('coverage')) + 1;
|
|
53
|
+
const others = pluginMetrics().filter(spec => spec.descriptor.scope === 'file' && !spec.ratioPart && !kinds.includes(spec));
|
|
54
|
+
return [builtinColumns[0], ...builtinColumns.slice(1, afterCoverage), ...pluginColumns(kinds), ...builtinColumns.slice(afterCoverage),
|
|
55
|
+
...pluginColumns(others)];
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* The Columns menu: a checkbox per column the scope can show, each remembered once changed. The path always shows;
|
|
59
|
+
* a sort by a column that is hidden falls back to it.
|
|
60
|
+
*/
|
|
61
|
+
export function columnMenu(columns, settings, scope, change) {
|
|
62
|
+
const menu = element('details', 'fx-columns');
|
|
63
|
+
const toggles = element('div', 'fx-column-toggles');
|
|
64
|
+
menu.append(element('summary', '', 'Columns'), toggles);
|
|
65
|
+
dismissible(menu);
|
|
66
|
+
const isVisible = (index) => index === 0 || Boolean(toggles.querySelector(`[value="${index}"]`)?.checked);
|
|
67
|
+
const keepSort = () => {
|
|
68
|
+
if (isVisible(settings.sort))
|
|
69
|
+
return;
|
|
70
|
+
settings.sort = 0;
|
|
71
|
+
settings.ascending = true;
|
|
72
|
+
};
|
|
73
|
+
const opens = { ignored: scope.files.some(entry => entry.analysed === false), sized: sized(scope.files) };
|
|
74
|
+
columns.forEach((column, index) => {
|
|
75
|
+
if (index === 0 || column.available?.(scope.totals) === false)
|
|
76
|
+
return;
|
|
77
|
+
const label = element('label', 'fx-column-toggle', column.label);
|
|
78
|
+
const toggle = element('input');
|
|
79
|
+
toggle.type = 'checkbox';
|
|
80
|
+
toggle.value = String(index);
|
|
81
|
+
toggle.checked = settings.columns.get(index) ?? column.defaultVisible?.(scope.totals, opens) ?? true;
|
|
82
|
+
toggle.addEventListener('change', () => {
|
|
83
|
+
settings.columns.set(index, toggle.checked);
|
|
84
|
+
keepSort();
|
|
85
|
+
change();
|
|
86
|
+
});
|
|
87
|
+
label.prepend(toggle);
|
|
88
|
+
toggles.append(label);
|
|
89
|
+
});
|
|
90
|
+
keepSort();
|
|
91
|
+
return { menu, isVisible };
|
|
92
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { PublicHistoryEntry } from '../../json/wire/public-history-model.js';
|
|
2
|
+
export interface CommitPicker {
|
|
3
|
+
set(sha: string): void;
|
|
4
|
+
hidden: boolean;
|
|
5
|
+
}
|
|
6
|
+
/** The line under the list: how many commits match, or how many the branch has. */
|
|
7
|
+
export declare function pickerStatus(total: number, listed: number, typed: string, branch: string | undefined): string;
|
|
8
|
+
/**
|
|
9
|
+
* Renders the picker into the slot; picking a commit calls back with its SHA. The branch, when the configuration names
|
|
10
|
+
* one, heads the field: the commits are that branch's history.
|
|
11
|
+
*/
|
|
12
|
+
export declare function createCommitPicker(slot: HTMLElement, entries: readonly PublicHistoryEntry[], pick: (sha: string) => void, branch?: string): CommitPicker;
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import { authorLabel, commitIndex, dayTime, hit, marked, searchCommits, when } from './viewer-commits.js';
|
|
2
|
+
import { element } from './viewer-dom.js';
|
|
3
|
+
/** What a commit is called in the list: its subject, or its date where the history has no messages. */
|
|
4
|
+
function commitTitle(entry) {
|
|
5
|
+
const time = when(entry);
|
|
6
|
+
return entry.subject ?? (time === null ? '' : dayTime.format(new Date(time)));
|
|
7
|
+
}
|
|
8
|
+
function typedWords(text) {
|
|
9
|
+
return text.trim().toLowerCase().split(/\s+/).filter(Boolean);
|
|
10
|
+
}
|
|
11
|
+
/** The line under the list: how many commits match, or how many the branch has. */
|
|
12
|
+
export function pickerStatus(total, listed, typed, branch) {
|
|
13
|
+
if (total === 0)
|
|
14
|
+
return `No commits match “${typed}”`;
|
|
15
|
+
if (total > listed)
|
|
16
|
+
return `${listed} of ${total.toLocaleString()} ${typed ? 'matches' : 'commits'} · type to narrow`;
|
|
17
|
+
return `${total.toLocaleString()} ${total === 1 ? 'commit' : 'commits'}${branch && !typed ? ` on ${branch}` : ''}`;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The second line names who and when, then the tags: two fit, the rest fold into a count, and the tags the search
|
|
21
|
+
* found come first. The email appears only when the search found it.
|
|
22
|
+
*/
|
|
23
|
+
function metaLine(entry, words) {
|
|
24
|
+
const time = when(entry);
|
|
25
|
+
const meta = [authorLabel(entry.author, words), entry.subject && time !== null ? dayTime.format(new Date(time)) : null].filter(Boolean).join(' · ');
|
|
26
|
+
const tags = [...entry.tags ?? []].sort((a, b) => Number(hit(b, words)) - Number(hit(a, words)));
|
|
27
|
+
if (!meta && !tags.length)
|
|
28
|
+
return [];
|
|
29
|
+
const line = element('span', 'commit-option-meta');
|
|
30
|
+
line.append(marked('span', 'commit-meta', meta, words), ...tags.slice(0, 2).map(tag => marked('span', 'commit-tag', tag, words)));
|
|
31
|
+
if (tags.length > 2) {
|
|
32
|
+
const more = element('span', 'commit-tag commit-tag-more', `+${tags.length - 2}`);
|
|
33
|
+
more.title = tags.slice(2).join('\n');
|
|
34
|
+
line.append(more);
|
|
35
|
+
}
|
|
36
|
+
return [line];
|
|
37
|
+
}
|
|
38
|
+
function optionItem(entry, position, words, selected) {
|
|
39
|
+
const item = element('li', 'commit-option');
|
|
40
|
+
item.id = `commit-option-${position}`;
|
|
41
|
+
item.setAttribute('role', 'option');
|
|
42
|
+
item.setAttribute('aria-selected', String(selected));
|
|
43
|
+
const head = element('span', 'commit-option-head');
|
|
44
|
+
head.append(marked('span', 'commit-hash', entry.sha.slice(0, 7), words, true), marked('span', 'commit-subject', commitTitle(entry), words));
|
|
45
|
+
item.append(head, ...metaLine(entry, words));
|
|
46
|
+
item.addEventListener('mousedown', event => event.preventDefault());
|
|
47
|
+
return item;
|
|
48
|
+
}
|
|
49
|
+
function searchInput(searchable) {
|
|
50
|
+
const input = element('input', 'commit-search');
|
|
51
|
+
input.type = 'text';
|
|
52
|
+
input.autocomplete = 'off';
|
|
53
|
+
input.spellcheck = false;
|
|
54
|
+
input.placeholder = searchable ? 'Message, tag, author, date or hash' : 'Hash or date';
|
|
55
|
+
input.setAttribute('role', 'combobox');
|
|
56
|
+
input.setAttribute('aria-autocomplete', 'list');
|
|
57
|
+
input.setAttribute('aria-expanded', 'false');
|
|
58
|
+
return input;
|
|
59
|
+
}
|
|
60
|
+
function branchName(branch) {
|
|
61
|
+
const name = element('span', 'commit-branch', branch);
|
|
62
|
+
name.title = `Branch ${branch}`;
|
|
63
|
+
name.setAttribute('aria-hidden', 'true');
|
|
64
|
+
return name;
|
|
65
|
+
}
|
|
66
|
+
/** Arrows step through the open list and wrap around it; a page moves eight and stops at either end. */
|
|
67
|
+
const arrows = new Map([['ArrowDown', 1], ['ArrowUp', -1]]);
|
|
68
|
+
const pages = new Map([['PageDown', 8], ['PageUp', -8]]);
|
|
69
|
+
/**
|
|
70
|
+
* Renders the picker into the slot; picking a commit calls back with its SHA. The branch, when the configuration names
|
|
71
|
+
* one, heads the field: the commits are that branch's history.
|
|
72
|
+
*/
|
|
73
|
+
export function createCommitPicker(slot, entries, pick, branch) {
|
|
74
|
+
const index = commitIndex(entries);
|
|
75
|
+
const bySha = new Map(entries.map(entry => [entry.sha, entry]));
|
|
76
|
+
let current = entries[0].sha;
|
|
77
|
+
let active = 0;
|
|
78
|
+
let matches = [];
|
|
79
|
+
// One control: the field shows the selected commit and, once focused, takes the search; the list opens attached
|
|
80
|
+
// under it, inside the same frame.
|
|
81
|
+
const field = element('div', 'commit-field');
|
|
82
|
+
const input = searchInput(entries.some(entry => entry.subject || entry.author || entry.tags?.length));
|
|
83
|
+
const shown = element('span', 'commit-current');
|
|
84
|
+
shown.setAttribute('aria-hidden', 'true');
|
|
85
|
+
// The selected commit is drawn over the empty input, so both share one box after the branch.
|
|
86
|
+
const entry = element('span', 'commit-entry');
|
|
87
|
+
entry.append(input, shown);
|
|
88
|
+
if (branch)
|
|
89
|
+
field.append(branchName(branch));
|
|
90
|
+
field.append(entry);
|
|
91
|
+
const popover = element('div', 'commit-popover');
|
|
92
|
+
popover.hidden = true;
|
|
93
|
+
const list = element('ul', 'commit-options');
|
|
94
|
+
list.id = 'commit-options';
|
|
95
|
+
list.setAttribute('role', 'listbox');
|
|
96
|
+
list.setAttribute('aria-label', 'Commits');
|
|
97
|
+
input.setAttribute('aria-controls', list.id);
|
|
98
|
+
const status = element('p', 'commit-status');
|
|
99
|
+
status.setAttribute('aria-live', 'polite');
|
|
100
|
+
popover.append(list, status);
|
|
101
|
+
slot.replaceChildren(field, popover);
|
|
102
|
+
function label() {
|
|
103
|
+
const chosen = bySha.get(current);
|
|
104
|
+
shown.replaceChildren(element('span', 'commit-hash', chosen.sha.slice(0, 7)), element('span', 'commit-current-text', commitTitle(chosen)));
|
|
105
|
+
field.title = [chosen.sha, chosen.subject].filter(Boolean).join('\n');
|
|
106
|
+
const subject = chosen.subject ? `: ${chosen.subject}` : '';
|
|
107
|
+
input.setAttribute('aria-label', `${branch ? `Branch ${branch}, commit` : 'Commit'} ${chosen.sha.slice(0, 7)}${subject}. Type to search commits`);
|
|
108
|
+
}
|
|
109
|
+
function update() {
|
|
110
|
+
const typed = input.value.trim();
|
|
111
|
+
const result = searchCommits(index, input.value);
|
|
112
|
+
matches = result.matches;
|
|
113
|
+
active = typed ? 0 : Math.max(0, matches.findIndex(match => match.entry.sha === current));
|
|
114
|
+
const words = typedWords(input.value);
|
|
115
|
+
list.replaceChildren(...matches.map((match, position) => {
|
|
116
|
+
const item = optionItem(match.entry, position, words, match.entry.sha === current);
|
|
117
|
+
item.addEventListener('click', () => choose(match.entry.sha));
|
|
118
|
+
item.addEventListener('mousemove', () => {
|
|
119
|
+
if (active === position)
|
|
120
|
+
return;
|
|
121
|
+
active = position;
|
|
122
|
+
highlight();
|
|
123
|
+
});
|
|
124
|
+
return item;
|
|
125
|
+
}));
|
|
126
|
+
status.textContent = pickerStatus(result.total, matches.length, typed, branch);
|
|
127
|
+
highlight();
|
|
128
|
+
}
|
|
129
|
+
function highlight() {
|
|
130
|
+
for (const [position, item] of [...list.children].entries())
|
|
131
|
+
item.classList.toggle('active', position === active);
|
|
132
|
+
const item = list.children[active];
|
|
133
|
+
if (!item) {
|
|
134
|
+
input.removeAttribute('aria-activedescendant');
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
input.setAttribute('aria-activedescendant', item.id);
|
|
138
|
+
item.scrollIntoView({ block: 'nearest' });
|
|
139
|
+
}
|
|
140
|
+
const isOpen = () => !popover.hidden;
|
|
141
|
+
function open() {
|
|
142
|
+
if (isOpen())
|
|
143
|
+
return;
|
|
144
|
+
popover.hidden = false;
|
|
145
|
+
slot.classList.add('open');
|
|
146
|
+
input.setAttribute('aria-expanded', 'true');
|
|
147
|
+
update();
|
|
148
|
+
document.addEventListener('pointerdown', outside, true);
|
|
149
|
+
}
|
|
150
|
+
function close() {
|
|
151
|
+
if (!isOpen())
|
|
152
|
+
return;
|
|
153
|
+
popover.hidden = true;
|
|
154
|
+
slot.classList.remove('open');
|
|
155
|
+
input.setAttribute('aria-expanded', 'false');
|
|
156
|
+
input.removeAttribute('aria-activedescendant');
|
|
157
|
+
input.value = '';
|
|
158
|
+
document.removeEventListener('pointerdown', outside, true);
|
|
159
|
+
}
|
|
160
|
+
function outside(event) {
|
|
161
|
+
if (!slot.contains(event.target))
|
|
162
|
+
close();
|
|
163
|
+
}
|
|
164
|
+
function choose(sha) {
|
|
165
|
+
close();
|
|
166
|
+
input.blur();
|
|
167
|
+
if (sha !== current)
|
|
168
|
+
pick(sha);
|
|
169
|
+
}
|
|
170
|
+
function move(to) {
|
|
171
|
+
active = to;
|
|
172
|
+
highlight();
|
|
173
|
+
return true;
|
|
174
|
+
}
|
|
175
|
+
/** A page key moves through the list whether or not it is open, and keeps the page itself from scrolling. */
|
|
176
|
+
function pageKey(key) {
|
|
177
|
+
const by = pages.get(key);
|
|
178
|
+
return by !== undefined && move(Math.min(matches.length - 1, Math.max(0, active + by)));
|
|
179
|
+
}
|
|
180
|
+
/** What a key does while the list is open; whether it took the key from the browser. */
|
|
181
|
+
function openKey(key) {
|
|
182
|
+
const by = arrows.get(key);
|
|
183
|
+
if (by !== undefined)
|
|
184
|
+
return move(matches.length === 0 ? 0 : (active + by + matches.length) % matches.length);
|
|
185
|
+
if (key === 'Enter') {
|
|
186
|
+
const match = matches[active];
|
|
187
|
+
if (match)
|
|
188
|
+
choose(match.entry.sha);
|
|
189
|
+
return true;
|
|
190
|
+
}
|
|
191
|
+
if (key !== 'Escape')
|
|
192
|
+
return false;
|
|
193
|
+
close();
|
|
194
|
+
return true;
|
|
195
|
+
}
|
|
196
|
+
field.addEventListener('pointerdown', event => {
|
|
197
|
+
if (event.target !== input)
|
|
198
|
+
event.preventDefault();
|
|
199
|
+
input.focus();
|
|
200
|
+
open();
|
|
201
|
+
});
|
|
202
|
+
input.addEventListener('focus', open);
|
|
203
|
+
input.addEventListener('blur', () => { if (!slot.matches(':hover'))
|
|
204
|
+
close(); });
|
|
205
|
+
input.addEventListener('input', () => isOpen() ? update() : open());
|
|
206
|
+
input.addEventListener('keydown', event => {
|
|
207
|
+
// A closed list opens on the keys that would move through it or pick from it.
|
|
208
|
+
const opens = !isOpen() && (event.key === 'ArrowDown' || event.key === 'ArrowUp' || event.key === 'Enter');
|
|
209
|
+
if (opens)
|
|
210
|
+
open();
|
|
211
|
+
if (opens || pageKey(event.key) || (isOpen() && openKey(event.key)))
|
|
212
|
+
event.preventDefault();
|
|
213
|
+
});
|
|
214
|
+
label();
|
|
215
|
+
return {
|
|
216
|
+
set(sha) {
|
|
217
|
+
if (!bySha.has(sha))
|
|
218
|
+
return;
|
|
219
|
+
current = sha;
|
|
220
|
+
label();
|
|
221
|
+
},
|
|
222
|
+
get hidden() { return slot.hidden === true; },
|
|
223
|
+
set hidden(value) {
|
|
224
|
+
if (value)
|
|
225
|
+
close();
|
|
226
|
+
slot.hidden = value;
|
|
227
|
+
},
|
|
228
|
+
};
|
|
229
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { PublicHistoryEntry } from '../../json/wire/public-history-model.js';
|
|
2
|
+
export declare const dayTime: Intl.DateTimeFormat;
|
|
2
3
|
export interface CommitMatch {
|
|
3
4
|
readonly entry: PublicHistoryEntry;
|
|
4
5
|
readonly index: number;
|
|
@@ -19,18 +20,13 @@ export declare function searchCommits(index: readonly Indexed[], query: string,
|
|
|
19
20
|
matches: CommitMatch[];
|
|
20
21
|
total: number;
|
|
21
22
|
};
|
|
22
|
-
export interface CommitPicker {
|
|
23
|
-
set(sha: string): void;
|
|
24
|
-
hidden: boolean;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Renders the picker into the slot; picking a commit calls back with its SHA. The branch, when the configuration names
|
|
28
|
-
* one, heads the field: the commits are that branch's history.
|
|
29
|
-
*/
|
|
30
|
-
export declare function createCommitPicker(slot: HTMLElement, entries: readonly PublicHistoryEntry[], pick: (sha: string) => void, branch?: string): CommitPicker;
|
|
31
23
|
/**
|
|
32
24
|
* How a commit's author reads in the list: the name, with the email only when the search found the email and not the
|
|
33
25
|
* name. A history without emails carries the name alone, and then it is the name alone; nothing reads as missing.
|
|
34
26
|
*/
|
|
35
27
|
export declare function authorLabel(author: PublicHistoryEntry['author'], words: readonly string[]): string | null;
|
|
28
|
+
export declare function hit(text: string, words: readonly string[]): boolean;
|
|
29
|
+
export declare function when(entry: PublicHistoryEntry): number | null;
|
|
30
|
+
/** Text with the typed words marked; a hash is marked only from its start, as it is matched. */
|
|
31
|
+
export declare function marked(tag: 'span', className: string, text: string, words: readonly string[], prefixOnly?: boolean): HTMLElement;
|
|
36
32
|
export {};
|