repometry 0.4.2 → 0.6.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 +36 -14
- package/package.json +1 -1
- package/target/main/resources/report/json/comparison-v1.schema.json +6 -6
- package/target/main/resources/report/json/file-metrics-v1.schema.json +7 -6
- package/target/main/resources/report/json/pull-review-v1.schema.json +5 -5
- package/target/main/resources/report/json/report-v2.schema.json +210 -11
- package/target/main/resources/report/json/repository-summary-v1.schema.json +161 -14
- package/target/main/resources/report/json/viewer-inspection-v1.schema.json +518 -6
- package/target/main/resources/viewer/styles.css +7 -2
- package/target/main/ts/api/git/changes.d.ts +1 -1
- package/target/main/ts/api/git/changes.js +3 -3
- package/target/main/ts/api/git/commit-metadata.js +6 -4
- package/target/main/ts/api/git/git.d.ts +2 -1
- package/target/main/ts/api/git/git.js +16 -4
- package/target/main/ts/api/git/inspection-source.d.ts +1 -1
- package/target/main/ts/api/git/inspection-source.js +4 -10
- package/target/main/ts/api/git/local.d.ts +1 -1
- package/target/main/ts/api/git/local.js +41 -7
- 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/api/worker/remote-executor.d.ts +1 -1
- package/target/main/ts/api/worker/remote-executor.js +2 -2
- package/target/main/ts/api/worker/worker-protocol.d.ts +2 -2
- package/target/main/ts/api/worker/worker-protocol.js +8 -8
- package/target/main/ts/api/worker/worker.d.ts +1 -1
- package/target/main/ts/api/worker/worker.js +4 -4
- package/target/main/ts/cli/main.js +4 -3
- package/target/main/ts/cli/reporting.d.ts +1 -1
- package/target/main/ts/cli/reporting.js +1 -1
- package/target/main/ts/compose/analysis-files.d.ts +13 -0
- package/target/main/ts/compose/analysis-files.js +95 -0
- package/target/main/ts/compose/analysis-imports.d.ts +7 -0
- package/target/main/ts/compose/analysis-imports.js +34 -0
- package/target/main/ts/compose/analysis-report.d.ts +5 -0
- package/target/main/ts/compose/analysis-report.js +78 -0
- package/target/main/ts/compose/analysis-repository.d.ts +6 -0
- package/target/main/ts/compose/analysis-repository.js +61 -0
- package/target/main/ts/compose/analysis-results.d.ts +38 -0
- package/target/main/ts/compose/analysis-results.js +78 -0
- package/target/main/ts/compose/analysis-sources.d.ts +73 -0
- package/target/main/ts/compose/analysis-sources.js +47 -0
- package/target/main/ts/compose/analyze-snapshot.d.ts +3 -2
- package/target/main/ts/compose/analyze-snapshot.js +19 -197
- package/target/main/ts/compose/diff-coverage.d.ts +2 -0
- package/target/main/ts/compose/diff-coverage.js +6 -4
- package/target/main/ts/compose/inspect.d.ts +5 -0
- package/target/main/ts/compose/inspect.js +14 -7
- package/target/main/ts/compose/languages.d.ts +29 -0
- package/target/main/ts/compose/languages.js +87 -0
- package/target/main/ts/compose/sources.js +14 -12
- 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/manifest.d.ts +2 -2
- package/target/main/ts/core/engine/manifest.js +25 -5
- 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 +3 -4
- package/target/main/ts/core/engine/plan.js +28 -11
- package/target/main/ts/core/engine/plugin.d.ts +10 -2
- 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.d.ts +1 -0
- package/target/main/ts/core/model/clone-source.js +2 -1
- package/target/main/ts/core/model/code-structure.d.ts +5 -0
- package/target/main/ts/core/model/code-structure.js +10 -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/language.d.ts +10 -0
- package/target/main/ts/core/model/language.js +6 -0
- 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.d.ts +7 -6
- package/target/main/ts/core/model/measurement.js +18 -7
- package/target/main/ts/core/model/plugin-data.d.ts +5 -0
- package/target/main/ts/core/model/plugin-data.js +15 -1
- package/target/main/ts/core/model/quality-summary.js +6 -5
- package/target/main/ts/core/model/report.d.ts +1 -2
- package/target/main/ts/core/model/report.js +0 -1
- package/target/main/ts/core/model/scanner-import.js +1 -1
- package/target/main/ts/core/model/snapshot.d.ts +1 -2
- package/target/main/ts/core/model/snapshot.js +5 -7
- 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/core/usecases/compare.js +61 -17
- package/target/main/ts/core/usecases/inspect.js +2 -2
- package/target/main/ts/plugin.d.ts +10 -3
- package/target/main/ts/plugin.js +4 -2
- 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/duplication/duplication.js +10 -4
- package/target/main/ts/plugins/language-js/babel-provider.js +8 -2
- package/target/main/ts/plugins/language-js/extensions.d.ts +3 -0
- package/target/main/ts/plugins/language-js/extensions.js +4 -0
- 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/plugins/language-js/js-security.js +3 -2
- 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-data.d.ts +1 -1
- package/target/main/ts/report/html/app/viewer-data.js +2 -29
- 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 +7 -84
- 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 +118 -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 -365
- 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 +54 -0
- package/target/main/ts/report/html/app/viewer-trend-data.js +109 -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/export-site.d.ts +3 -4
- package/target/main/ts/report/html/site/export-site.js +24 -41
- package/target/main/ts/report/html/site/exported-server.js +2 -1
- package/target/main/ts/report/html/site/local-server.d.ts +1 -1
- package/target/main/ts/report/html/site/local-server.js +13 -19
- package/target/main/ts/report/html/site/projects.js +8 -17
- package/target/main/ts/report/json/projections/commit-summary.d.ts +2 -2
- package/target/main/ts/report/json/projections/commit-summary.js +18 -19
- package/target/main/ts/report/json/projections/file-metrics.js +31 -24
- package/target/main/ts/report/json/projections/inspection-context.js +10 -1
- package/target/main/ts/report/json/projections/inspection-details.d.ts +1 -1
- package/target/main/ts/report/json/projections/inspection-details.js +2 -2
- package/target/main/ts/report/json/projections/metric-values.d.ts +1 -0
- package/target/main/ts/report/json/projections/metric-values.js +15 -5
- 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/pull-review-store.js +1 -2
- 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/json/validation/report.d.ts +1 -1
- package/target/main/ts/report/json/validation/report.js +10 -8
- package/target/main/ts/report/json/validation/summary-validation.js +1 -3
- package/target/main/ts/report/json/wire/file-metrics-model.d.ts +2 -0
- package/target/main/ts/report/json/wire/inspection-details-model.d.ts +0 -5
- package/target/main/ts/report/json/wire/public-history-model.d.ts +0 -6
- package/target/main/ts/report/json/wire/public-history-model.js +0 -1
- package/target/main/ts/report.d.ts +3 -3
- package/target/main/ts/report.js +2 -2
- package/target/main/resources/report/json/inspection-context-v1.schema.json +0 -172
- package/target/main/resources/report/json/public-history-v1.schema.json +0 -50
- package/target/main/resources/report/json/quality-history-v1.schema.json +0 -51
- package/target/main/resources/report/json/report-v1.schema.json +0 -65
- package/target/main/resources/report/json/viewer-details-v1.schema.json +0 -346
- package/target/main/ts/report/json/projections/public-history.d.ts +0 -4
- package/target/main/ts/report/json/projections/public-history.js +0 -17
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { element } from './viewer-dom.js';
|
|
1
2
|
const shown = 50;
|
|
2
3
|
const day = new Intl.DateTimeFormat(undefined, { day: 'numeric', month: 'short', year: 'numeric' });
|
|
3
|
-
const dayTime = new Intl.DateTimeFormat(undefined, { day: 'numeric', month: 'short', year: 'numeric', hour: '2-digit', minute: '2-digit' });
|
|
4
|
+
export const dayTime = new Intl.DateTimeFormat(undefined, { day: 'numeric', month: 'short', year: 'numeric', hour: '2-digit', minute: '2-digit' });
|
|
4
5
|
export function commitIndex(entries) {
|
|
5
6
|
return entries.map(entry => {
|
|
6
7
|
const time = when(entry);
|
|
@@ -31,199 +32,6 @@ export function searchCommits(index, query, limit = shown) {
|
|
|
31
32
|
}
|
|
32
33
|
return { matches: [...exact, ...rest].slice(0, limit), total };
|
|
33
34
|
}
|
|
34
|
-
/**
|
|
35
|
-
* Renders the picker into the slot; picking a commit calls back with its SHA. The branch, when the configuration names
|
|
36
|
-
* one, heads the field: the commits are that branch's history.
|
|
37
|
-
*/
|
|
38
|
-
export function createCommitPicker(slot, entries, pick, branch) {
|
|
39
|
-
const index = commitIndex(entries);
|
|
40
|
-
const bySha = new Map(entries.map(entry => [entry.sha, entry]));
|
|
41
|
-
const searchable = entries.some(entry => entry.subject || entry.author || entry.tags?.length);
|
|
42
|
-
let current = entries[0].sha;
|
|
43
|
-
let active = 0;
|
|
44
|
-
let matches = [];
|
|
45
|
-
// One control: the field shows the selected commit and, once focused, takes the search; the list opens attached
|
|
46
|
-
// under it, inside the same frame.
|
|
47
|
-
const field = element('div', 'commit-field');
|
|
48
|
-
const input = element('input', 'commit-search');
|
|
49
|
-
input.type = 'text';
|
|
50
|
-
input.autocomplete = 'off';
|
|
51
|
-
input.spellcheck = false;
|
|
52
|
-
input.placeholder = searchable ? 'Message, tag, author, date or hash' : 'Hash or date';
|
|
53
|
-
input.setAttribute('role', 'combobox');
|
|
54
|
-
input.setAttribute('aria-autocomplete', 'list');
|
|
55
|
-
input.setAttribute('aria-expanded', 'false');
|
|
56
|
-
const shown = element('span', 'commit-current');
|
|
57
|
-
shown.setAttribute('aria-hidden', 'true');
|
|
58
|
-
// The selected commit is drawn over the empty input, so both share one box after the branch.
|
|
59
|
-
const entry = element('span', 'commit-entry');
|
|
60
|
-
entry.append(input, shown);
|
|
61
|
-
if (branch) {
|
|
62
|
-
const name = element('span', 'commit-branch', branch);
|
|
63
|
-
name.title = `Branch ${branch}`;
|
|
64
|
-
name.setAttribute('aria-hidden', 'true');
|
|
65
|
-
field.append(name);
|
|
66
|
-
}
|
|
67
|
-
field.append(entry);
|
|
68
|
-
const popover = element('div', 'commit-popover');
|
|
69
|
-
popover.hidden = true;
|
|
70
|
-
const list = element('ul', 'commit-options');
|
|
71
|
-
list.id = 'commit-options';
|
|
72
|
-
list.setAttribute('role', 'listbox');
|
|
73
|
-
list.setAttribute('aria-label', 'Commits');
|
|
74
|
-
input.setAttribute('aria-controls', list.id);
|
|
75
|
-
const status = element('p', 'commit-status');
|
|
76
|
-
status.setAttribute('aria-live', 'polite');
|
|
77
|
-
popover.append(list, status);
|
|
78
|
-
slot.replaceChildren(field, popover);
|
|
79
|
-
function label() {
|
|
80
|
-
const entry = bySha.get(current);
|
|
81
|
-
const time = when(entry);
|
|
82
|
-
shown.replaceChildren(element('span', 'commit-hash', entry.sha.slice(0, 7)), element('span', 'commit-current-text', entry.subject ?? (time === null ? '' : dayTime.format(new Date(time)))));
|
|
83
|
-
field.title = [entry.sha, entry.subject].filter(Boolean).join('\n');
|
|
84
|
-
input.setAttribute('aria-label', `${branch ? `Branch ${branch}, commit` : 'Commit'} ${entry.sha.slice(0, 7)}${entry.subject ? `: ${entry.subject}` : ''}. Type to search commits`);
|
|
85
|
-
}
|
|
86
|
-
function update() {
|
|
87
|
-
const result = searchCommits(index, input.value);
|
|
88
|
-
matches = result.matches;
|
|
89
|
-
active = Math.max(0, matches.findIndex(match => match.entry.sha === current));
|
|
90
|
-
if (input.value.trim())
|
|
91
|
-
active = 0;
|
|
92
|
-
const words = input.value.trim().toLowerCase().split(/\s+/).filter(Boolean);
|
|
93
|
-
list.replaceChildren(...matches.map((match, position) => option(match.entry, position, words)));
|
|
94
|
-
status.textContent = result.total === 0 ? `No commits match “${input.value.trim()}”`
|
|
95
|
-
: result.total > matches.length ? `${matches.length} of ${result.total.toLocaleString()} ${input.value.trim() ? 'matches' : 'commits'} · type to narrow`
|
|
96
|
-
: `${result.total.toLocaleString()} ${result.total === 1 ? 'commit' : 'commits'}${branch && !input.value.trim() ? ` on ${branch}` : ''}`;
|
|
97
|
-
highlight();
|
|
98
|
-
}
|
|
99
|
-
function option(entry, position, words) {
|
|
100
|
-
const item = element('li', 'commit-option');
|
|
101
|
-
item.id = `commit-option-${position}`;
|
|
102
|
-
item.setAttribute('role', 'option');
|
|
103
|
-
item.setAttribute('aria-selected', String(entry.sha === current));
|
|
104
|
-
const time = when(entry);
|
|
105
|
-
const head = element('span', 'commit-option-head');
|
|
106
|
-
head.append(marked('span', 'commit-hash', entry.sha.slice(0, 7), words, true), marked('span', 'commit-subject', entry.subject ?? (time === null ? '' : dayTime.format(new Date(time))), words));
|
|
107
|
-
item.append(head);
|
|
108
|
-
// The second line names who and when, then the tags: two fit, the rest fold into a count, and the tags the
|
|
109
|
-
// search found come first. The email appears only when the search found it.
|
|
110
|
-
const author = authorLabel(entry.author, words);
|
|
111
|
-
const meta = [author, entry.subject && time !== null ? dayTime.format(new Date(time)) : null].filter(Boolean).join(' · ');
|
|
112
|
-
const tags = [...entry.tags ?? []].sort((a, b) => Number(hit(b, words)) - Number(hit(a, words)));
|
|
113
|
-
if (meta || tags.length) {
|
|
114
|
-
const line = element('span', 'commit-option-meta');
|
|
115
|
-
line.append(marked('span', 'commit-meta', meta, words));
|
|
116
|
-
for (const tag of tags.slice(0, 2))
|
|
117
|
-
line.append(marked('span', 'commit-tag', tag, words));
|
|
118
|
-
if (tags.length > 2) {
|
|
119
|
-
const more = element('span', 'commit-tag commit-tag-more', `+${tags.length - 2}`);
|
|
120
|
-
more.title = tags.slice(2).join('\n');
|
|
121
|
-
line.append(more);
|
|
122
|
-
}
|
|
123
|
-
item.append(line);
|
|
124
|
-
}
|
|
125
|
-
item.addEventListener('mousedown', event => event.preventDefault());
|
|
126
|
-
item.addEventListener('click', () => choose(entry.sha));
|
|
127
|
-
item.addEventListener('mousemove', () => { if (active !== position) {
|
|
128
|
-
active = position;
|
|
129
|
-
highlight();
|
|
130
|
-
} });
|
|
131
|
-
return item;
|
|
132
|
-
}
|
|
133
|
-
function highlight() {
|
|
134
|
-
for (const [position, item] of [...list.children].entries())
|
|
135
|
-
item.classList.toggle('active', position === active);
|
|
136
|
-
const item = list.children[active];
|
|
137
|
-
if (item) {
|
|
138
|
-
input.setAttribute('aria-activedescendant', item.id);
|
|
139
|
-
item.scrollIntoView({ block: 'nearest' });
|
|
140
|
-
}
|
|
141
|
-
else
|
|
142
|
-
input.removeAttribute('aria-activedescendant');
|
|
143
|
-
}
|
|
144
|
-
const isOpen = () => !popover.hidden;
|
|
145
|
-
function open() {
|
|
146
|
-
if (isOpen())
|
|
147
|
-
return;
|
|
148
|
-
popover.hidden = false;
|
|
149
|
-
slot.classList.add('open');
|
|
150
|
-
input.setAttribute('aria-expanded', 'true');
|
|
151
|
-
update();
|
|
152
|
-
document.addEventListener('pointerdown', outside, true);
|
|
153
|
-
}
|
|
154
|
-
function close() {
|
|
155
|
-
if (!isOpen())
|
|
156
|
-
return;
|
|
157
|
-
popover.hidden = true;
|
|
158
|
-
slot.classList.remove('open');
|
|
159
|
-
input.setAttribute('aria-expanded', 'false');
|
|
160
|
-
input.removeAttribute('aria-activedescendant');
|
|
161
|
-
input.value = '';
|
|
162
|
-
document.removeEventListener('pointerdown', outside, true);
|
|
163
|
-
}
|
|
164
|
-
function outside(event) {
|
|
165
|
-
if (!slot.contains(event.target))
|
|
166
|
-
close();
|
|
167
|
-
}
|
|
168
|
-
function choose(sha) {
|
|
169
|
-
close();
|
|
170
|
-
input.blur();
|
|
171
|
-
if (sha !== current)
|
|
172
|
-
pick(sha);
|
|
173
|
-
}
|
|
174
|
-
field.addEventListener('pointerdown', event => {
|
|
175
|
-
if (event.target !== input)
|
|
176
|
-
event.preventDefault();
|
|
177
|
-
input.focus();
|
|
178
|
-
open();
|
|
179
|
-
});
|
|
180
|
-
input.addEventListener('focus', open);
|
|
181
|
-
input.addEventListener('blur', () => { if (!slot.matches(':hover'))
|
|
182
|
-
close(); });
|
|
183
|
-
input.addEventListener('input', () => isOpen() ? update() : open());
|
|
184
|
-
input.addEventListener('keydown', event => {
|
|
185
|
-
const last = matches.length - 1;
|
|
186
|
-
if (!isOpen() && (event.key === 'ArrowDown' || event.key === 'ArrowUp' || event.key === 'Enter')) {
|
|
187
|
-
event.preventDefault();
|
|
188
|
-
open();
|
|
189
|
-
}
|
|
190
|
-
else if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
|
|
191
|
-
event.preventDefault();
|
|
192
|
-
active = last < 0 ? 0 : (active + (event.key === 'ArrowDown' ? 1 : -1) + matches.length) % matches.length;
|
|
193
|
-
highlight();
|
|
194
|
-
}
|
|
195
|
-
else if (event.key === 'PageDown' || event.key === 'PageUp') {
|
|
196
|
-
event.preventDefault();
|
|
197
|
-
active = Math.min(last, Math.max(0, active + (event.key === 'PageDown' ? 8 : -8)));
|
|
198
|
-
highlight();
|
|
199
|
-
}
|
|
200
|
-
else if (event.key === 'Enter') {
|
|
201
|
-
event.preventDefault();
|
|
202
|
-
const match = matches[active];
|
|
203
|
-
if (match)
|
|
204
|
-
choose(match.entry.sha);
|
|
205
|
-
}
|
|
206
|
-
else if (event.key === 'Escape' && isOpen()) {
|
|
207
|
-
event.preventDefault();
|
|
208
|
-
close();
|
|
209
|
-
}
|
|
210
|
-
});
|
|
211
|
-
label();
|
|
212
|
-
return {
|
|
213
|
-
set(sha) {
|
|
214
|
-
if (!bySha.has(sha))
|
|
215
|
-
return;
|
|
216
|
-
current = sha;
|
|
217
|
-
label();
|
|
218
|
-
},
|
|
219
|
-
get hidden() { return slot.hidden === true; },
|
|
220
|
-
set hidden(value) {
|
|
221
|
-
if (value)
|
|
222
|
-
close();
|
|
223
|
-
slot.hidden = value;
|
|
224
|
-
},
|
|
225
|
-
};
|
|
226
|
-
}
|
|
227
35
|
/**
|
|
228
36
|
* How a commit's author reads in the list: the name, with the email only when the search found the email and not the
|
|
229
37
|
* name. A history without emails carries the name alone, and then it is the name alone; nothing reads as missing.
|
|
@@ -233,31 +41,32 @@ export function authorLabel(author, words) {
|
|
|
233
41
|
return null;
|
|
234
42
|
return author.email && hit(author.email, words) && !hit(author.name, words) ? `${author.name} <${author.email}>` : author.name;
|
|
235
43
|
}
|
|
236
|
-
function hit(text, words) {
|
|
44
|
+
export function hit(text, words) {
|
|
237
45
|
const lower = text.toLowerCase();
|
|
238
46
|
return words.some(word => lower.includes(word));
|
|
239
47
|
}
|
|
240
|
-
function when(entry) {
|
|
48
|
+
export function when(entry) {
|
|
241
49
|
const time = Date.parse(entry.committedAt ?? entry.generatedAt);
|
|
242
50
|
return Number.isFinite(time) ? time : null;
|
|
243
51
|
}
|
|
244
|
-
/**
|
|
245
|
-
function
|
|
246
|
-
const node = element(tag, className);
|
|
247
|
-
const lower = text.toLowerCase();
|
|
52
|
+
/** Where the typed words stand in the text, in order; a hash is matched only from its start. */
|
|
53
|
+
function wordRanges(lower, words, prefixOnly) {
|
|
248
54
|
const ranges = [];
|
|
249
55
|
for (const word of words) {
|
|
250
|
-
if (prefixOnly) {
|
|
251
|
-
|
|
252
|
-
ranges.push([
|
|
253
|
-
continue;
|
|
56
|
+
if (!prefixOnly) {
|
|
57
|
+
for (let at = lower.indexOf(word); at >= 0; at = lower.indexOf(word, at + word.length))
|
|
58
|
+
ranges.push([at, at + word.length]);
|
|
254
59
|
}
|
|
255
|
-
|
|
256
|
-
ranges.push([
|
|
60
|
+
else if (lower.startsWith(word))
|
|
61
|
+
ranges.push([0, word.length]);
|
|
257
62
|
}
|
|
258
|
-
ranges.sort((a, b) => a[0] - b[0]);
|
|
63
|
+
return ranges.sort((a, b) => a[0] - b[0]);
|
|
64
|
+
}
|
|
65
|
+
/** Text with the typed words marked; a hash is marked only from its start, as it is matched. */
|
|
66
|
+
export function marked(tag, className, text, words, prefixOnly = false) {
|
|
67
|
+
const node = element(tag, className);
|
|
259
68
|
let cursor = 0;
|
|
260
|
-
for (const [start, end] of
|
|
69
|
+
for (const [start, end] of wordRanges(text.toLowerCase(), words, prefixOnly)) {
|
|
261
70
|
if (end <= cursor)
|
|
262
71
|
continue;
|
|
263
72
|
const from = Math.max(start, cursor);
|
|
@@ -270,11 +79,3 @@ function marked(tag, className, text, words, prefixOnly = false) {
|
|
|
270
79
|
node.append(text.slice(cursor));
|
|
271
80
|
return node;
|
|
272
81
|
}
|
|
273
|
-
function element(tag, className, text) {
|
|
274
|
-
const node = document.createElement(tag);
|
|
275
|
-
if (className)
|
|
276
|
-
node.className = className;
|
|
277
|
-
if (text !== undefined)
|
|
278
|
-
node.textContent = text;
|
|
279
|
-
return node;
|
|
280
|
-
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export declare function searchField(text: string, placeholder: string): {
|
|
2
|
+
label: HTMLLabelElement;
|
|
3
|
+
input: HTMLInputElement;
|
|
4
|
+
};
|
|
5
|
+
/** Two or three exclusive views as one segmented switch; the pressed segment is the current view. */
|
|
6
|
+
export declare function segmented(text: string, options: readonly (readonly [string, string])[], selected: string, change: (value: string) => void): HTMLElement;
|
|
7
|
+
/** Presses the segment with this name, as a click on it would look, without running its change. */
|
|
8
|
+
export declare function pressSegment(group: HTMLElement, name: string): void;
|
|
9
|
+
/** A details menu that closes on a click elsewhere or on Escape, as a menu does. */
|
|
10
|
+
export declare function dismissible(menu: HTMLDetailsElement): void;
|
|
11
|
+
/** What a multiple choice's button says: all, up to two names, or how many are chosen. */
|
|
12
|
+
export declare function chosenLabel(chosen: readonly string[], all: string, plural: string): string;
|
|
13
|
+
/** What a multiple choice is called, what it says with nothing ticked, and what it counts with many. */
|
|
14
|
+
export interface ChoiceNames {
|
|
15
|
+
readonly text: string;
|
|
16
|
+
readonly all: string;
|
|
17
|
+
readonly plural: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* A dropdown of checkboxes: none ticked means all. The button names what is chosen, so the filter reads at a glance;
|
|
21
|
+
* each option carries its count. It hides itself when there is nothing to choose between.
|
|
22
|
+
*/
|
|
23
|
+
export declare function multiChoice({ text, all, plural }: ChoiceNames, options: readonly (readonly [string, string, number])[], change: () => void, initial?: Iterable<string>): {
|
|
24
|
+
element: HTMLDetailsElement;
|
|
25
|
+
values: Set<string>;
|
|
26
|
+
};
|
|
27
|
+
export declare function choice(text: string, options: readonly (readonly [string, string])[], selected: string): {
|
|
28
|
+
label: HTMLLabelElement;
|
|
29
|
+
select: HTMLSelectElement;
|
|
30
|
+
};
|
|
31
|
+
/** A select's options: the catch-all first, then each distinct value by its label. */
|
|
32
|
+
export declare function choices<T extends string>(first: string, values: readonly T[], labels?: Readonly<Partial<Record<T, string>>>): [string, string][];
|
|
33
|
+
export declare function navigationButtons(label: string, previous: () => void, next: () => void): {
|
|
34
|
+
section: HTMLElement;
|
|
35
|
+
update: (page: number, pages: number) => void;
|
|
36
|
+
};
|
|
37
|
+
/** A paged list's state: its buttons, and the page they move, rendered again on each move. */
|
|
38
|
+
export declare function pager(label: string, render: () => void): {
|
|
39
|
+
page: number;
|
|
40
|
+
} & {
|
|
41
|
+
section: HTMLElement;
|
|
42
|
+
update: (page: number, pages: number) => void;
|
|
43
|
+
};
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { collator, count, element } from './viewer-dom.js';
|
|
2
|
+
export function searchField(text, placeholder) {
|
|
3
|
+
const label = element('label', 'fx-field');
|
|
4
|
+
label.append(element('span', 'fx-field-text', text));
|
|
5
|
+
const input = element('input');
|
|
6
|
+
input.type = 'search';
|
|
7
|
+
input.placeholder = placeholder;
|
|
8
|
+
input.spellcheck = false;
|
|
9
|
+
label.append(input);
|
|
10
|
+
return { label, input };
|
|
11
|
+
}
|
|
12
|
+
/** Two or three exclusive views as one segmented switch; the pressed segment is the current view. */
|
|
13
|
+
export function segmented(text, options, selected, change) {
|
|
14
|
+
const group = element('div', 'fx-segmented');
|
|
15
|
+
group.setAttribute('role', 'group');
|
|
16
|
+
group.setAttribute('aria-label', text);
|
|
17
|
+
const buttons = options.map(([value, name]) => {
|
|
18
|
+
const button = element('button', '', name);
|
|
19
|
+
button.type = 'button';
|
|
20
|
+
button.setAttribute('aria-pressed', String(value === selected));
|
|
21
|
+
button.addEventListener('click', () => {
|
|
22
|
+
for (const other of buttons)
|
|
23
|
+
other.setAttribute('aria-pressed', String(other === button));
|
|
24
|
+
change(value);
|
|
25
|
+
});
|
|
26
|
+
return button;
|
|
27
|
+
});
|
|
28
|
+
group.append(...buttons);
|
|
29
|
+
return group;
|
|
30
|
+
}
|
|
31
|
+
/** Presses the segment with this name, as a click on it would look, without running its change. */
|
|
32
|
+
export function pressSegment(group, name) {
|
|
33
|
+
group.querySelectorAll('button').forEach(button => button.setAttribute('aria-pressed', String(button.textContent === name)));
|
|
34
|
+
}
|
|
35
|
+
/** A details menu that closes on a click elsewhere or on Escape, as a menu does. */
|
|
36
|
+
export function dismissible(menu) {
|
|
37
|
+
const close = (event) => {
|
|
38
|
+
const key = event instanceof KeyboardEvent;
|
|
39
|
+
if (key ? event.key !== 'Escape' : menu.contains(event.target))
|
|
40
|
+
return;
|
|
41
|
+
if (menu.open && key)
|
|
42
|
+
menu.querySelector('summary')?.focus();
|
|
43
|
+
menu.open = false;
|
|
44
|
+
};
|
|
45
|
+
menu.addEventListener('toggle', () => {
|
|
46
|
+
const listen = menu.open ? document.addEventListener.bind(document) : document.removeEventListener.bind(document);
|
|
47
|
+
listen('pointerdown', close, true);
|
|
48
|
+
listen('keydown', close);
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
/** What a multiple choice's button says: all, up to two names, or how many are chosen. */
|
|
52
|
+
export function chosenLabel(chosen, all, plural) {
|
|
53
|
+
if (chosen.length === 0)
|
|
54
|
+
return all;
|
|
55
|
+
// Two choices read by name, so a filtered view says what it holds; more read as a count.
|
|
56
|
+
return chosen.length <= 2 ? chosen.join(', ') : `${chosen.length} ${plural}`;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* A dropdown of checkboxes: none ticked means all. The button names what is chosen, so the filter reads at a glance;
|
|
60
|
+
* each option carries its count. It hides itself when there is nothing to choose between.
|
|
61
|
+
*/
|
|
62
|
+
export function multiChoice({ text, all, plural }, options, change, initial = []) {
|
|
63
|
+
const offered = new Set(options.map(([value]) => value));
|
|
64
|
+
const values = new Set([...initial].filter(value => offered.has(value)));
|
|
65
|
+
const menu = element('details', 'fx-columns fx-multi');
|
|
66
|
+
menu.hidden = options.length < 2;
|
|
67
|
+
const summary = element('summary', '', all);
|
|
68
|
+
summary.setAttribute('aria-label', `${text}: ${all}`);
|
|
69
|
+
const list = element('div', 'fx-column-toggles');
|
|
70
|
+
list.setAttribute('role', 'group');
|
|
71
|
+
list.setAttribute('aria-label', text);
|
|
72
|
+
function label() {
|
|
73
|
+
const chosen = options.filter(([value]) => values.has(value)).map(([, name]) => name);
|
|
74
|
+
summary.textContent = chosenLabel(chosen, all, plural);
|
|
75
|
+
summary.title = chosen.join(', ');
|
|
76
|
+
summary.setAttribute('aria-label', `${text}: ${chosen.length ? chosen.join(', ') : all}`);
|
|
77
|
+
menu.classList.toggle('fx-multi-active', chosen.length > 0);
|
|
78
|
+
}
|
|
79
|
+
for (const [value, name, total] of options) {
|
|
80
|
+
const row = element('label', 'fx-column-toggle');
|
|
81
|
+
const box = element('input');
|
|
82
|
+
box.type = 'checkbox';
|
|
83
|
+
box.value = value;
|
|
84
|
+
box.checked = values.has(value);
|
|
85
|
+
box.addEventListener('change', () => {
|
|
86
|
+
if (box.checked)
|
|
87
|
+
values.add(value);
|
|
88
|
+
else
|
|
89
|
+
values.delete(value);
|
|
90
|
+
label();
|
|
91
|
+
change();
|
|
92
|
+
});
|
|
93
|
+
row.append(box, element('span', 'fx-multi-name', name), element('span', 'fx-multi-count', total.toLocaleString()));
|
|
94
|
+
list.append(row);
|
|
95
|
+
}
|
|
96
|
+
menu.append(summary, list);
|
|
97
|
+
dismissible(menu);
|
|
98
|
+
label();
|
|
99
|
+
return { element: menu, values };
|
|
100
|
+
}
|
|
101
|
+
export function choice(text, options, selected) {
|
|
102
|
+
const label = element('label', 'fx-field');
|
|
103
|
+
label.append(element('span', 'fx-field-text', text));
|
|
104
|
+
const select = element('select');
|
|
105
|
+
for (const [value, name] of options) {
|
|
106
|
+
const option = element('option', '', name);
|
|
107
|
+
option.value = value;
|
|
108
|
+
select.append(option);
|
|
109
|
+
}
|
|
110
|
+
select.value = selected;
|
|
111
|
+
label.append(select);
|
|
112
|
+
return { label, select };
|
|
113
|
+
}
|
|
114
|
+
/** A select's options: the catch-all first, then each distinct value by its label. */
|
|
115
|
+
export function choices(first, values, labels) {
|
|
116
|
+
const unique = [...new Set(values)].map(value => [value, labels?.[value] ?? value]);
|
|
117
|
+
return [['', first], ...unique.sort((a, b) => collator.compare(a[1], b[1]))];
|
|
118
|
+
}
|
|
119
|
+
export function navigationButtons(label, previous, next) {
|
|
120
|
+
const section = element('nav', 'fx-page-buttons');
|
|
121
|
+
section.setAttribute('aria-label', label);
|
|
122
|
+
const back = element('button', 'button', 'Previous');
|
|
123
|
+
const forward = element('button', 'button', 'Next');
|
|
124
|
+
back.type = forward.type = 'button';
|
|
125
|
+
back.addEventListener('click', previous);
|
|
126
|
+
forward.addEventListener('click', next);
|
|
127
|
+
const pageLabel = element('span', 'fx-note');
|
|
128
|
+
pageLabel.setAttribute('aria-live', 'polite');
|
|
129
|
+
section.append(back, pageLabel, forward);
|
|
130
|
+
return { section, update: (page, pages) => {
|
|
131
|
+
back.disabled = page === 0;
|
|
132
|
+
forward.disabled = page + 1 >= pages;
|
|
133
|
+
pageLabel.textContent = `${count(page + 1)} of ${count(pages)}`;
|
|
134
|
+
} };
|
|
135
|
+
}
|
|
136
|
+
/** A paged list's state: its buttons, and the page they move, rendered again on each move. */
|
|
137
|
+
export function pager(label, render) {
|
|
138
|
+
const state = { page: 0 };
|
|
139
|
+
const buttons = navigationButtons(label, () => { state.page--; render(); }, () => { state.page++; render(); });
|
|
140
|
+
return Object.assign(state, buttons);
|
|
141
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
interface CopyFeedback {
|
|
2
|
+
/** The text is on the clipboard; the button shows its check until `reset`. */
|
|
3
|
+
copied(): void;
|
|
4
|
+
reset(): void;
|
|
5
|
+
/** The browser refused the clipboard: the reader copies by hand. */
|
|
6
|
+
refused(): void;
|
|
7
|
+
}
|
|
8
|
+
/** Copies the text on each click, with a check that fades after a moment, or the fallback the browser leaves. */
|
|
9
|
+
export declare function copyOnClick(button: HTMLButtonElement, text: () => string, feedback: CopyFeedback): void;
|
|
10
|
+
/**
|
|
11
|
+
* Copies a file's path from the repository root. Where the browser refuses the clipboard, `show` puts the path on the
|
|
12
|
+
* page and it is selected, for the reader's own copy shortcut.
|
|
13
|
+
*/
|
|
14
|
+
export declare function copyPathButton(path: string, show: () => HTMLElement): HTMLButtonElement;
|
|
15
|
+
/** The common copy glyph, two offset sheets, with the check it turns into once copied. */
|
|
16
|
+
export declare function copyIcon(): SVGSVGElement;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { element, svgElement } from './viewer-dom.js';
|
|
2
|
+
/** Copies the text on each click, with a check that fades after a moment, or the fallback the browser leaves. */
|
|
3
|
+
export function copyOnClick(button, text, feedback) {
|
|
4
|
+
let timer;
|
|
5
|
+
button.addEventListener('click', async () => {
|
|
6
|
+
clearTimeout(timer);
|
|
7
|
+
try {
|
|
8
|
+
if (!navigator.clipboard)
|
|
9
|
+
throw new Error('Clipboard unavailable');
|
|
10
|
+
await navigator.clipboard.writeText(text());
|
|
11
|
+
button.classList.add('fx-copied');
|
|
12
|
+
feedback.copied();
|
|
13
|
+
timer = setTimeout(() => {
|
|
14
|
+
button.classList.remove('fx-copied');
|
|
15
|
+
feedback.reset();
|
|
16
|
+
}, 1500);
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
feedback.refused();
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Copies a file's path from the repository root. Where the browser refuses the clipboard, `show` puts the path on the
|
|
25
|
+
* page and it is selected, for the reader's own copy shortcut.
|
|
26
|
+
*/
|
|
27
|
+
export function copyPathButton(path, show) {
|
|
28
|
+
const label = 'Copy path';
|
|
29
|
+
const copy = element('button', 'fx-copy fx-copy-inline');
|
|
30
|
+
copy.type = 'button';
|
|
31
|
+
copy.title = `${label}: ${path}`;
|
|
32
|
+
copy.setAttribute('aria-label', label);
|
|
33
|
+
copy.append(copyIcon());
|
|
34
|
+
const status = element('span', 'visually-hidden');
|
|
35
|
+
status.setAttribute('role', 'status');
|
|
36
|
+
copy.append(status);
|
|
37
|
+
copyOnClick(copy, () => path, {
|
|
38
|
+
copied: () => { status.textContent = 'Path copied'; },
|
|
39
|
+
reset: () => { status.textContent = ''; },
|
|
40
|
+
refused: () => {
|
|
41
|
+
window.getSelection()?.selectAllChildren(show());
|
|
42
|
+
status.textContent = 'Path selected. Press your copy shortcut.';
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
return copy;
|
|
46
|
+
}
|
|
47
|
+
/** The common copy glyph, two offset sheets, with the check it turns into once copied. */
|
|
48
|
+
export function copyIcon() {
|
|
49
|
+
const svg = svgElement('svg');
|
|
50
|
+
svg.setAttribute('viewBox', '0 0 16 16');
|
|
51
|
+
svg.setAttribute('aria-hidden', 'true');
|
|
52
|
+
const shapes = [
|
|
53
|
+
['rect', { class: 'fx-copy-sheets', x: '5.5', y: '5.5', width: '8', height: '8', rx: '1.5' }],
|
|
54
|
+
['path', { class: 'fx-copy-sheets', d: 'M10.5 3.5v-.5A1.5 1.5 0 0 0 9 1.5H3A1.5 1.5 0 0 0 1.5 3v6A1.5 1.5 0 0 0 3 10.5h.5' }],
|
|
55
|
+
['path', { class: 'fx-copy-check', d: 'M3 8.5l3 3 7-7' }],
|
|
56
|
+
];
|
|
57
|
+
for (const [tag, attributes] of shapes) {
|
|
58
|
+
const shape = svgElement(tag);
|
|
59
|
+
for (const [name, value] of Object.entries(attributes))
|
|
60
|
+
shape.setAttribute(name, value);
|
|
61
|
+
svg.append(shape);
|
|
62
|
+
}
|
|
63
|
+
return svg;
|
|
64
|
+
}
|
|
@@ -7,7 +7,7 @@ export interface ViewerData {
|
|
|
7
7
|
readonly reports: readonly PublicHistoryEntry[];
|
|
8
8
|
readonly quality: QualityHistory['reports'];
|
|
9
9
|
readonly context: Record<string, InspectionContext>;
|
|
10
|
-
readonly counts
|
|
10
|
+
readonly counts: Record<string, InspectionCounts | undefined>;
|
|
11
11
|
readonly pullReviewCount?: number;
|
|
12
12
|
/** The branch whose first-parent history the commits are, when the configuration names it. */
|
|
13
13
|
readonly branch?: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
// The viewer's data: the repository summary, which lists every inspected commit, and each commit's inspection on demand.
|
|
1
2
|
import { unpackJson } from '../../json/wire/compact-json.js';
|
|
2
3
|
import { summarySchema } from '../../json/wire/summary-model.js';
|
|
3
|
-
import { compareHistoryEntries, historySchema } from '../../json/wire/public-history-model.js';
|
|
4
4
|
import { sourceLocator } from './viewer-source.js';
|
|
5
5
|
const shaPattern = /^(?:[a-f0-9]{40}|[a-f0-9]{64})$/;
|
|
6
6
|
export class ViewerSummaryChanged extends Error {
|
|
@@ -11,8 +11,6 @@ export class ViewerSummaryChanged extends Error {
|
|
|
11
11
|
}
|
|
12
12
|
export async function loadViewerData(mode) {
|
|
13
13
|
const summary = await readSummary();
|
|
14
|
-
if (!summary)
|
|
15
|
-
return legacyViewerData(mode);
|
|
16
14
|
const counts = Object.fromEntries(summary.commits.map(commit => [commit.sha, commit.counts]));
|
|
17
15
|
const details = new Map(summary.commits.map(commit => [commit.sha, commit.detail]));
|
|
18
16
|
return {
|
|
@@ -47,8 +45,6 @@ export async function loadViewerData(mode) {
|
|
|
47
45
|
}
|
|
48
46
|
async function readSummary(cache) {
|
|
49
47
|
const response = await fetch('./summary.json', { cache });
|
|
50
|
-
if (response.status === 404)
|
|
51
|
-
return null;
|
|
52
48
|
if (!response.ok)
|
|
53
49
|
throw new Error('Could not load the repository summary');
|
|
54
50
|
const data = await response.json();
|
|
@@ -57,6 +53,7 @@ async function readSummary(cache) {
|
|
|
57
53
|
throw new Error('Unsupported repository summary');
|
|
58
54
|
return data;
|
|
59
55
|
}
|
|
56
|
+
/** A commit's inspection, where the summary's path names one: `inspection/` when served locally, `details/` in an export. */
|
|
60
57
|
async function readInspection(path, sha, mode) {
|
|
61
58
|
const prefix = `${mode === 'local' ? 'inspection' : 'details'}/${sha}-`;
|
|
62
59
|
const allowed = path.startsWith(prefix) && /^[a-f0-9]{64}\.json$/.test(path.slice(prefix.length));
|
|
@@ -70,30 +67,6 @@ async function readInspection(path, sha, mode) {
|
|
|
70
67
|
return null;
|
|
71
68
|
}
|
|
72
69
|
}
|
|
73
|
-
async function legacyViewerData(mode) {
|
|
74
|
-
const [history, quality, saved, localContext] = await Promise.all([
|
|
75
|
-
readOptional('./history.json'),
|
|
76
|
-
readOptional('./quality-history.json'),
|
|
77
|
-
mode === 'local' ? null : readOptional('./details.json'),
|
|
78
|
-
mode === 'local' ? readOptional('./inspection-context.json') : null,
|
|
79
|
-
]);
|
|
80
|
-
if (history?.schema !== historySchema || !Array.isArray(history.reports))
|
|
81
|
-
throw new Error('Unsupported history format');
|
|
82
|
-
const bundle = saved?.schema === 'urn:repometry:schema:viewer-details:1' ? saved : null;
|
|
83
|
-
const context = localContext ?? bundle?.context ?? {};
|
|
84
|
-
const reports = [...history.reports].sort(compareHistoryEntries);
|
|
85
|
-
return {
|
|
86
|
-
reports, context, quality: quality?.schema === 'urn:repometry:schema:quality-history:1' ? quality.reports : {},
|
|
87
|
-
async loadDetails(sha) {
|
|
88
|
-
if (!shaPattern.test(sha))
|
|
89
|
-
return null;
|
|
90
|
-
const inspection = mode === 'local'
|
|
91
|
-
? await readOptional(`./details/${sha}.json`)
|
|
92
|
-
: bundle?.inspections[sha];
|
|
93
|
-
return inspection ? { schema: 'urn:repometry:schema:viewer-inspection:1', sha, context: context[sha], inspection } : null;
|
|
94
|
-
},
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
70
|
async function readOptional(path) {
|
|
98
71
|
try {
|
|
99
72
|
const response = await fetch(path);
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { InspectionDetails } from '../../json/wire/inspection-details-model.js';
|
|
2
|
+
import type { Navigation } from './viewer-inspection.js';
|
|
3
|
+
/** The Diagnostics page: what the analysis could not do, filtered by a search, an operation and a state. */
|
|
4
|
+
export declare function diagnosticsView(details: InspectionDetails, navigation: Navigation): HTMLElement;
|