repometry 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +28 -2
- package/package.json +64 -4
- package/target/main/resources/report/json/compact-json-v1.schema.json +24 -0
- package/target/main/resources/report/json/comparison-v1.schema.json +65 -0
- package/target/main/resources/report/json/config-v1.schema.json +33 -0
- package/target/main/resources/report/json/diff-coverage-v1.schema.json +55 -0
- package/target/main/resources/report/json/file-metrics-v1.schema.json +134 -0
- package/target/main/resources/report/json/inspection-context-v1.schema.json +172 -0
- package/target/main/resources/report/json/metabranch-v1.schema.json +9 -0
- package/target/main/resources/report/json/metric-catalog-v1.schema.json +31 -0
- package/target/main/resources/report/json/public-history-v1.schema.json +50 -0
- package/target/main/resources/report/json/pull-review-v1.schema.json +97 -0
- package/target/main/resources/report/json/quality-history-v1.schema.json +51 -0
- package/target/main/resources/report/json/report-v1.schema.json +65 -0
- package/target/main/resources/report/json/report-v2.schema.json +252 -0
- package/target/main/resources/report/json/repository-summary-v1.schema.json +181 -0
- package/target/main/resources/report/json/viewer-details-v1.schema.json +343 -0
- package/target/main/resources/report/json/viewer-inspection-v1.schema.json +13 -0
- package/target/main/resources/viewer/files.css +578 -0
- package/target/main/resources/viewer/index.html +120 -0
- package/target/main/resources/viewer/projects.html +52 -0
- package/target/main/resources/viewer/styles.css +560 -0
- package/target/main/resources/viewer/viewer-pulls.css +64 -0
- package/target/main/ts/api/gh/github.d.ts +6 -0
- package/target/main/ts/api/gh/github.js +92 -0
- package/target/main/ts/api/git/blob-batch.d.ts +10 -0
- package/target/main/ts/api/git/blob-batch.js +106 -0
- package/target/main/ts/api/git/changes.d.ts +22 -0
- package/target/main/ts/api/git/changes.js +108 -0
- package/target/main/ts/api/git/commit-metadata.d.ts +3 -0
- package/target/main/ts/api/git/commit-metadata.js +53 -0
- package/target/main/ts/api/git/git-churn.d.ts +9 -0
- package/target/main/ts/api/git/git-churn.js +71 -0
- package/target/main/ts/api/git/git-reader.d.ts +16 -0
- package/target/main/ts/api/git/git-reader.js +74 -0
- package/target/main/ts/api/git/git.d.ts +21 -0
- package/target/main/ts/api/git/git.js +153 -0
- package/target/main/ts/api/git/inspection-source.d.ts +15 -0
- package/target/main/ts/api/git/inspection-source.js +31 -0
- package/target/main/ts/api/git/local-sources.d.ts +5 -0
- package/target/main/ts/api/git/local-sources.js +47 -0
- package/target/main/ts/api/git/local.d.ts +3 -0
- package/target/main/ts/api/git/local.js +36 -0
- package/target/main/ts/api/git/metabranch-worktree.d.ts +1 -0
- package/target/main/ts/api/git/metabranch-worktree.js +35 -0
- package/target/main/ts/api/git/source-cache.d.ts +3 -0
- package/target/main/ts/api/git/source-cache.js +57 -0
- package/target/main/ts/api/import/finding-import.d.ts +9 -0
- package/target/main/ts/api/import/finding-import.js +227 -0
- package/target/main/ts/api/import/lcov-files.d.ts +5 -0
- package/target/main/ts/api/import/lcov-files.js +14 -0
- package/target/main/ts/api/import/profile-file.d.ts +4 -0
- package/target/main/ts/api/import/profile-file.js +17 -0
- package/target/main/ts/api/worker/remote-executor.d.ts +2 -0
- package/target/main/ts/api/worker/remote-executor.js +46 -0
- package/target/main/ts/api/worker/worker-protocol.d.ts +7 -0
- package/target/main/ts/api/worker/worker-protocol.js +102 -0
- package/target/main/ts/api/worker/worker.d.ts +5 -0
- package/target/main/ts/api/worker/worker.js +86 -0
- package/target/main/ts/cli/arguments.d.ts +28 -0
- package/target/main/ts/cli/arguments.js +111 -0
- package/target/main/ts/cli/config.d.ts +13 -0
- package/target/main/ts/cli/config.js +58 -0
- package/target/main/ts/cli/imports.d.ts +7 -0
- package/target/main/ts/cli/imports.js +30 -0
- package/target/main/ts/cli/main.d.ts +2 -0
- package/target/main/ts/cli/main.js +379 -0
- package/target/main/ts/cli/reporting.d.ts +18 -0
- package/target/main/ts/cli/reporting.js +104 -0
- package/target/main/ts/cli/revisions.d.ts +6 -0
- package/target/main/ts/cli/revisions.js +16 -0
- package/target/main/ts/cli/store.d.ts +13 -0
- package/target/main/ts/cli/store.js +39 -0
- package/target/main/ts/compose/analyze-snapshot.d.ts +4 -0
- package/target/main/ts/compose/analyze-snapshot.js +164 -0
- package/target/main/ts/compose/attach-churn.d.ts +2 -0
- package/target/main/ts/compose/attach-churn.js +50 -0
- package/target/main/ts/compose/diff-coverage.d.ts +20 -0
- package/target/main/ts/compose/diff-coverage.js +57 -0
- package/target/main/ts/compose/inspect.d.ts +23 -0
- package/target/main/ts/compose/inspect.js +45 -0
- package/target/main/ts/compose/plugin-list.d.ts +6 -0
- package/target/main/ts/compose/plugin-list.js +10 -0
- package/target/main/ts/compose/prepare-metabranch.d.ts +9 -0
- package/target/main/ts/compose/prepare-metabranch.js +17 -0
- package/target/main/ts/compose/review.d.ts +16 -0
- package/target/main/ts/compose/review.js +39 -0
- package/target/main/ts/compose/sources.d.ts +3 -0
- package/target/main/ts/compose/sources.js +30 -0
- package/target/main/ts/core/engine/execute.d.ts +10 -0
- package/target/main/ts/core/engine/execute.js +50 -0
- package/target/main/ts/core/engine/manifest.d.ts +4 -0
- package/target/main/ts/core/engine/manifest.js +105 -0
- package/target/main/ts/core/engine/plan.d.ts +22 -0
- package/target/main/ts/core/engine/plan.js +107 -0
- package/target/main/ts/core/engine/plugin.d.ts +59 -0
- package/target/main/ts/core/engine/plugin.js +4 -0
- package/target/main/ts/core/engine/report-products.d.ts +16 -0
- package/target/main/ts/core/engine/report-products.js +86 -0
- package/target/main/ts/core/model/changes.d.ts +8 -0
- package/target/main/ts/core/model/changes.js +2 -0
- package/target/main/ts/core/model/churn.d.ts +11 -0
- package/target/main/ts/core/model/churn.js +5 -0
- package/target/main/ts/core/model/clone-source.d.ts +16 -0
- package/target/main/ts/core/model/clone-source.js +15 -0
- package/target/main/ts/core/model/code-structure.d.ts +30 -0
- package/target/main/ts/core/model/code-structure.js +32 -0
- package/target/main/ts/core/model/comparison.d.ts +24 -0
- package/target/main/ts/core/model/comparison.js +1 -0
- package/target/main/ts/core/model/diff-coverage.d.ts +23 -0
- package/target/main/ts/core/model/diff-coverage.js +1 -0
- package/target/main/ts/core/model/finding-ignore.d.ts +8 -0
- package/target/main/ts/core/model/finding-ignore.js +36 -0
- package/target/main/ts/core/model/finding.d.ts +28 -0
- package/target/main/ts/core/model/finding.js +29 -0
- package/target/main/ts/core/model/ignore-rule.d.ts +11 -0
- package/target/main/ts/core/model/ignore-rule.js +1 -0
- package/target/main/ts/core/model/measurement.d.ts +33 -0
- package/target/main/ts/core/model/measurement.js +30 -0
- package/target/main/ts/core/model/metric-descriptor.d.ts +17 -0
- package/target/main/ts/core/model/metric-descriptor.js +1 -0
- package/target/main/ts/core/model/plugin-data.d.ts +25 -0
- package/target/main/ts/core/model/plugin-data.js +1 -0
- package/target/main/ts/core/model/pull-review.d.ts +48 -0
- package/target/main/ts/core/model/pull-review.js +1 -0
- package/target/main/ts/core/model/quality-summary.d.ts +42 -0
- package/target/main/ts/core/model/quality-summary.js +64 -0
- package/target/main/ts/core/model/report.d.ts +40 -0
- package/target/main/ts/core/model/report.js +5 -0
- package/target/main/ts/core/model/scanner-import.d.ts +39 -0
- package/target/main/ts/core/model/scanner-import.js +29 -0
- package/target/main/ts/core/model/snapshot.d.ts +15 -0
- package/target/main/ts/core/model/snapshot.js +51 -0
- package/target/main/ts/core/model/source-locator.d.ts +7 -0
- package/target/main/ts/core/model/source-locator.js +1 -0
- package/target/main/ts/core/model/source.d.ts +23 -0
- package/target/main/ts/core/model/source.js +1 -0
- package/target/main/ts/core/ports/report.d.ts +9 -0
- package/target/main/ts/core/ports/report.js +2 -0
- package/target/main/ts/core/ports/source-provider.d.ts +14 -0
- package/target/main/ts/core/ports/source-provider.js +5 -0
- package/target/main/ts/core/profile/exclusions.d.ts +11 -0
- package/target/main/ts/core/profile/exclusions.js +58 -0
- package/target/main/ts/core/profile/maintainability.d.ts +31 -0
- package/target/main/ts/core/profile/maintainability.js +10 -0
- package/target/main/ts/core/profile/profile.d.ts +4 -0
- package/target/main/ts/core/profile/profile.js +11 -0
- package/target/main/ts/core/usecases/compare.d.ts +6 -0
- package/target/main/ts/core/usecases/compare.js +146 -0
- package/target/main/ts/core/usecases/diff-coverage-policy.d.ts +6 -0
- package/target/main/ts/core/usecases/diff-coverage-policy.js +11 -0
- package/target/main/ts/core/usecases/diff-coverage.d.ts +40 -0
- package/target/main/ts/core/usecases/diff-coverage.js +16 -0
- package/target/main/ts/core/usecases/inspect.d.ts +38 -0
- package/target/main/ts/core/usecases/inspect.js +42 -0
- package/target/main/ts/core/usecases/review.d.ts +31 -0
- package/target/main/ts/core/usecases/review.js +129 -0
- package/target/main/ts/index.d.ts +35 -0
- package/target/main/ts/index.js +18 -0
- package/target/main/ts/plugin.d.ts +14 -0
- package/target/main/ts/plugin.js +6 -0
- package/target/main/ts/plugins/coverage/coverage.d.ts +25 -0
- package/target/main/ts/plugins/coverage/coverage.js +199 -0
- package/target/main/ts/plugins/coverage/diff-coverage.d.ts +7 -0
- package/target/main/ts/plugins/coverage/diff-coverage.js +90 -0
- package/target/main/ts/plugins/duplication/duplication.d.ts +4 -0
- package/target/main/ts/plugins/duplication/duplication.js +94 -0
- package/target/main/ts/plugins/language-js/babel-provider.d.ts +10 -0
- package/target/main/ts/plugins/language-js/babel-provider.js +47 -0
- package/target/main/ts/plugins/language-js/clone-candidates.d.ts +3 -0
- package/target/main/ts/plugins/language-js/clone-candidates.js +65 -0
- package/target/main/ts/plugins/language-js/code-lines.d.ts +6 -0
- package/target/main/ts/plugins/language-js/code-lines.js +36 -0
- package/target/main/ts/plugins/language-js/function-facts.d.ts +8 -0
- package/target/main/ts/plugins/language-js/function-facts.js +61 -0
- package/target/main/ts/plugins/language-js/structural-observations.d.ts +8 -0
- package/target/main/ts/plugins/language-js/structural-observations.js +80 -0
- package/target/main/ts/plugins/maintainability/maintainability.d.ts +9 -0
- package/target/main/ts/plugins/maintainability/maintainability.js +43 -0
- package/target/main/ts/plugins/maintainability/structural-smells.d.ts +3 -0
- package/target/main/ts/plugins/maintainability/structural-smells.js +16 -0
- package/target/main/ts/plugins/source/forges.d.ts +4 -0
- package/target/main/ts/plugins/source/forges.js +80 -0
- package/target/main/ts/plugins/structure/structure.d.ts +2 -0
- package/target/main/ts/plugins/structure/structure.js +38 -0
- package/target/main/ts/report/html/app/viewer-chart.d.ts +101 -0
- package/target/main/ts/report/html/app/viewer-chart.js +711 -0
- package/target/main/ts/report/html/app/viewer-commits.d.ts +36 -0
- package/target/main/ts/report/html/app/viewer-commits.js +280 -0
- package/target/main/ts/report/html/app/viewer-data.d.ts +23 -0
- package/target/main/ts/report/html/app/viewer-data.js +105 -0
- package/target/main/ts/report/html/app/viewer-files.d.ts +117 -0
- package/target/main/ts/report/html/app/viewer-files.js +2104 -0
- package/target/main/ts/report/html/app/viewer-filter.d.ts +113 -0
- package/target/main/ts/report/html/app/viewer-filter.js +492 -0
- package/target/main/ts/report/html/app/viewer-metric-registry.d.ts +70 -0
- package/target/main/ts/report/html/app/viewer-metric-registry.js +224 -0
- package/target/main/ts/report/html/app/viewer-metrics.d.ts +44 -0
- package/target/main/ts/report/html/app/viewer-metrics.js +172 -0
- package/target/main/ts/report/html/app/viewer-profile.d.ts +17 -0
- package/target/main/ts/report/html/app/viewer-profile.js +401 -0
- package/target/main/ts/report/html/app/viewer-projects.d.ts +1 -0
- package/target/main/ts/report/html/app/viewer-projects.js +90 -0
- package/target/main/ts/report/html/app/viewer-pulls.d.ts +3 -0
- package/target/main/ts/report/html/app/viewer-pulls.js +242 -0
- package/target/main/ts/report/html/app/viewer-source.d.ts +75 -0
- package/target/main/ts/report/html/app/viewer-source.js +313 -0
- package/target/main/ts/report/html/app/viewer-trends.d.ts +73 -0
- package/target/main/ts/report/html/app/viewer-trends.js +423 -0
- package/target/main/ts/report/html/app/viewer.d.ts +1 -0
- package/target/main/ts/report/html/app/viewer.js +735 -0
- package/target/main/ts/report/html/site/badges.d.ts +14 -0
- package/target/main/ts/report/html/site/badges.js +40 -0
- package/target/main/ts/report/html/site/export-site.d.ts +22 -0
- package/target/main/ts/report/html/site/export-site.js +150 -0
- package/target/main/ts/report/html/site/exported-server.d.ts +6 -0
- package/target/main/ts/report/html/site/exported-server.js +71 -0
- package/target/main/ts/report/html/site/local-server.d.ts +7 -0
- package/target/main/ts/report/html/site/local-server.js +65 -0
- package/target/main/ts/report/html/site/projects.d.ts +3 -0
- package/target/main/ts/report/html/site/projects.js +80 -0
- package/target/main/ts/report/html/site/server.d.ts +4 -0
- package/target/main/ts/report/html/site/server.js +65 -0
- package/target/main/ts/report/html/site/source-route.d.ts +6 -0
- package/target/main/ts/report/html/site/source-route.js +23 -0
- package/target/main/ts/report/json/projections/commit-summary.d.ts +12 -0
- package/target/main/ts/report/json/projections/commit-summary.js +124 -0
- package/target/main/ts/report/json/projections/components.d.ts +4 -0
- package/target/main/ts/report/json/projections/components.js +30 -0
- package/target/main/ts/report/json/projections/file-metrics.d.ts +5 -0
- package/target/main/ts/report/json/projections/file-metrics.js +244 -0
- package/target/main/ts/report/json/projections/inspection-context.d.ts +6 -0
- package/target/main/ts/report/json/projections/inspection-context.js +93 -0
- package/target/main/ts/report/json/projections/inspection-details.d.ts +11 -0
- package/target/main/ts/report/json/projections/inspection-details.js +70 -0
- package/target/main/ts/report/json/projections/metric-values.d.ts +7 -0
- package/target/main/ts/report/json/projections/metric-values.js +58 -0
- package/target/main/ts/report/json/projections/public-history.d.ts +4 -0
- package/target/main/ts/report/json/projections/public-history.js +17 -0
- package/target/main/ts/report/json/store/components.d.ts +2 -0
- package/target/main/ts/report/json/store/components.js +32 -0
- package/target/main/ts/report/json/store/local-store.d.ts +13 -0
- package/target/main/ts/report/json/store/local-store.js +180 -0
- package/target/main/ts/report/json/store/pull-review-store.d.ts +3 -0
- package/target/main/ts/report/json/store/pull-review-store.js +52 -0
- package/target/main/ts/report/json/validation/metabranch.d.ts +4 -0
- package/target/main/ts/report/json/validation/metabranch.js +8 -0
- package/target/main/ts/report/json/validation/report.d.ts +15 -0
- package/target/main/ts/report/json/validation/report.js +65 -0
- package/target/main/ts/report/json/validation/summary-validation.d.ts +4 -0
- package/target/main/ts/report/json/validation/summary-validation.js +28 -0
- package/target/main/ts/report/json/wire/compact-json.d.ts +11 -0
- package/target/main/ts/report/json/wire/compact-json.js +76 -0
- package/target/main/ts/report/json/wire/component-model.d.ts +9 -0
- package/target/main/ts/report/json/wire/component-model.js +1 -0
- package/target/main/ts/report/json/wire/domain-types.d.ts +2 -0
- package/target/main/ts/report/json/wire/domain-types.js +1 -0
- package/target/main/ts/report/json/wire/file-metrics-model.d.ts +77 -0
- package/target/main/ts/report/json/wire/file-metrics-model.js +1 -0
- package/target/main/ts/report/json/wire/inspection-context-model.d.ts +26 -0
- package/target/main/ts/report/json/wire/inspection-context-model.js +1 -0
- package/target/main/ts/report/json/wire/inspection-details-model.d.ts +82 -0
- package/target/main/ts/report/json/wire/inspection-details-model.js +1 -0
- package/target/main/ts/report/json/wire/project-model.d.ts +7 -0
- package/target/main/ts/report/json/wire/project-model.js +1 -0
- package/target/main/ts/report/json/wire/public-history-model.d.ts +42 -0
- package/target/main/ts/report/json/wire/public-history-model.js +6 -0
- package/target/main/ts/report/json/wire/pull-review-model.d.ts +7 -0
- package/target/main/ts/report/json/wire/pull-review-model.js +1 -0
- package/target/main/ts/report/json/wire/summary-model.d.ts +45 -0
- package/target/main/ts/report/json/wire/summary-model.js +1 -0
- package/target/main/ts/report.d.ts +11 -0
- package/target/main/ts/report.js +6 -0
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import type { FileMetricsReport } from '../../json/wire/file-metrics-model.js';
|
|
2
|
+
type FileEntry = FileMetricsReport['files'][number];
|
|
3
|
+
/** A built-in measure, or another plugin's metric by its registry key. */
|
|
4
|
+
export type Measure = string;
|
|
5
|
+
export type Operator = '>' | '>=' | '<' | '<=' | '=';
|
|
6
|
+
export type Clause = {
|
|
7
|
+
readonly kind: 'lang';
|
|
8
|
+
readonly value: string;
|
|
9
|
+
} | {
|
|
10
|
+
readonly kind: 'component';
|
|
11
|
+
readonly value: string;
|
|
12
|
+
} | {
|
|
13
|
+
readonly kind: 'path';
|
|
14
|
+
readonly value: string;
|
|
15
|
+
} | {
|
|
16
|
+
readonly kind: 'measure';
|
|
17
|
+
readonly measure: Measure;
|
|
18
|
+
readonly operator: Operator;
|
|
19
|
+
readonly value: number;
|
|
20
|
+
} | {
|
|
21
|
+
readonly kind: 'has';
|
|
22
|
+
readonly value: 'findings' | 'diagnostics';
|
|
23
|
+
}
|
|
24
|
+
/** Whether a plugin read the file: `ignored:yes` lists what is only counted, lockfiles aside. */
|
|
25
|
+
| {
|
|
26
|
+
readonly kind: 'analysed';
|
|
27
|
+
readonly value: 'yes' | 'no';
|
|
28
|
+
}
|
|
29
|
+
/** Generated dependency lockfiles: `lockfile:yes`. */
|
|
30
|
+
| {
|
|
31
|
+
readonly kind: 'lockfile';
|
|
32
|
+
readonly value: 'yes' | 'no';
|
|
33
|
+
};
|
|
34
|
+
/** What a file brings to the query beyond its metrics: the components it belongs to and its open findings. */
|
|
35
|
+
export interface FileFacts {
|
|
36
|
+
readonly components: ReadonlyMap<string, readonly string[]>;
|
|
37
|
+
readonly findings: ReadonlyMap<string, number>;
|
|
38
|
+
}
|
|
39
|
+
export interface MeasureSpec {
|
|
40
|
+
readonly label: string;
|
|
41
|
+
readonly percent?: boolean;
|
|
42
|
+
readonly minutes?: boolean;
|
|
43
|
+
read(entry: FileEntry): number | null;
|
|
44
|
+
}
|
|
45
|
+
export declare function usePluginMeasures(entries: Iterable<readonly [string, MeasureSpec]>): void;
|
|
46
|
+
/**
|
|
47
|
+
* Dependency lockfiles, by exact file name. They are generated, often the largest files in a repository, and no
|
|
48
|
+
* plugin reads them: the language bar and the Metrics list give them a category of their own beside the ignored files.
|
|
49
|
+
*/
|
|
50
|
+
export declare const lockfileNames: ReadonlySet<string>;
|
|
51
|
+
/** Whether a path names a lockfile: its file name, at any depth, exactly as the tools write it. */
|
|
52
|
+
export declare function isLockfile(path: string): boolean;
|
|
53
|
+
/** Whether no plugin read a file and it is not a lockfile: what the interface calls ignored. */
|
|
54
|
+
export declare function isIgnored(entry: Pick<FileEntry, 'path' | 'analysed'>): boolean;
|
|
55
|
+
/** The language bar's names for the two categories that are not languages. */
|
|
56
|
+
export declare const lockfilesLabel = "Lockfiles";
|
|
57
|
+
export declare const ignoredLabel = "Ignored";
|
|
58
|
+
/** What the language bar weighs: size in bytes, physical lines, or code lines. */
|
|
59
|
+
export type ShareMeasure = 'bytes' | 'lines' | 'code-lines';
|
|
60
|
+
/** Whether every file carries its size: inspections made before sizes were recorded carry none. */
|
|
61
|
+
export declare function sized(files: readonly Pick<FileEntry, 'bytes'>[]): boolean;
|
|
62
|
+
/**
|
|
63
|
+
* What the language bar weighs, largest language first, then lockfiles, then the ignored files. Size in bytes when
|
|
64
|
+
* every file has it: one measure for code, lockfiles and ignored files alike, untouched by formatting. Without sizes,
|
|
65
|
+
* physical lines where any file is only counted (the one line measure all files have), otherwise code lines.
|
|
66
|
+
*/
|
|
67
|
+
export declare function languageShares(files: readonly Pick<FileEntry, 'path' | 'analysed' | 'lines' | 'quality' | 'bytes'>[]): {
|
|
68
|
+
readonly measure: ShareMeasure;
|
|
69
|
+
readonly shares: readonly (readonly [string, number])[];
|
|
70
|
+
};
|
|
71
|
+
export declare function languageOf(path: string): string;
|
|
72
|
+
export declare function languageColor(language: string): string;
|
|
73
|
+
/** Splits the query into clauses; a word that names nothing known becomes a path fragment. */
|
|
74
|
+
export declare function parseQuery(text: string): Clause[];
|
|
75
|
+
export declare function parseWord(word: string): Clause | null;
|
|
76
|
+
export declare function formatQuery(clauses: readonly Clause[]): string;
|
|
77
|
+
export declare function clauseText(clause: Clause): string;
|
|
78
|
+
/** The chip's words: what it selects, in the interface's language rather than the query's. */
|
|
79
|
+
export declare function clauseLabel(clause: Clause): {
|
|
80
|
+
key: string;
|
|
81
|
+
value: string;
|
|
82
|
+
};
|
|
83
|
+
export declare function sameClause(a: Clause, b: Clause): boolean;
|
|
84
|
+
/**
|
|
85
|
+
* Whether a file passes the query. Chips of one kind widen the selection (TypeScript or JavaScript), chips of
|
|
86
|
+
* different kinds narrow it (TypeScript in the core component), and every condition must hold.
|
|
87
|
+
*/
|
|
88
|
+
export declare function matches(entry: FileEntry, clauses: readonly Clause[], facts: FileFacts, text?: string): boolean;
|
|
89
|
+
export interface Suggestion {
|
|
90
|
+
readonly group: string;
|
|
91
|
+
readonly label: string;
|
|
92
|
+
readonly detail?: string;
|
|
93
|
+
readonly clause: Clause;
|
|
94
|
+
readonly color?: string;
|
|
95
|
+
}
|
|
96
|
+
/** What the field offers for the typed text: the facets of this codebase first, then conditions, then the path. */
|
|
97
|
+
export declare function suggest(text: string, files: readonly FileEntry[], facts: FileFacts, chosen: readonly Clause[]): Suggestion[];
|
|
98
|
+
export interface QueryField {
|
|
99
|
+
readonly element: HTMLElement;
|
|
100
|
+
/** Text typed but not yet made a chip; it filters paths as you type. */
|
|
101
|
+
readonly text: () => string;
|
|
102
|
+
/** Replaces the chips from outside, as when a language is picked on the bar; reports the change as typing does. */
|
|
103
|
+
readonly set: (clauses: readonly Clause[]) => void;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* The field: chips for the chosen clauses, then a text input; the list of suggestions hangs from it in one frame.
|
|
107
|
+
* Backspace in an empty input takes the last chip back into text, so a chip can be edited, not just removed.
|
|
108
|
+
*/
|
|
109
|
+
export declare function queryField(clauses: readonly Clause[], options: {
|
|
110
|
+
readonly suggestions: (text: string) => Suggestion[];
|
|
111
|
+
readonly change: (clauses: readonly Clause[], text: string) => void;
|
|
112
|
+
}): QueryField;
|
|
113
|
+
export {};
|
|
@@ -0,0 +1,492 @@
|
|
|
1
|
+
import { labelOf } from './viewer-metrics.js';
|
|
2
|
+
const measures = {
|
|
3
|
+
complexity: { label: labelOf('complexity'), read: entry => entry.complexity?.maximum ?? null },
|
|
4
|
+
cognitive: { label: labelOf('cognitive'), read: entry => entry.quality?.cognitiveComplexity ?? null },
|
|
5
|
+
lines: { label: labelOf('code-lines'), read: entry => entry.quality?.codeLines ?? entry.lines },
|
|
6
|
+
functions: { label: 'Functions', read: entry => entry.functions },
|
|
7
|
+
coverage: { label: labelOf('coverage'), percent: true,
|
|
8
|
+
read: entry => entry.lineCoverage && entry.lineCoverage.total > 0 ? entry.lineCoverage.covered / entry.lineCoverage.total : null },
|
|
9
|
+
duplication: { label: 'Duplication', percent: true, read: entry => {
|
|
10
|
+
const duplication = entry.quality?.duplication;
|
|
11
|
+
return duplication && duplication.codeLines > 0 ? duplication.duplicatedLines / duplication.codeLines : null;
|
|
12
|
+
} },
|
|
13
|
+
remediation: { label: labelOf('effort'), minutes: true, read: entry => entry.quality?.maintainability?.effortMinutes ?? null },
|
|
14
|
+
changes: { label: 'Git changes', read: entry => entry.quality?.churn ?? null },
|
|
15
|
+
};
|
|
16
|
+
/** Other plugins' metrics, by key, for the inspection on screen. */
|
|
17
|
+
let pluginMeasures = new Map();
|
|
18
|
+
export function usePluginMeasures(entries) {
|
|
19
|
+
pluginMeasures = new Map(entries);
|
|
20
|
+
}
|
|
21
|
+
function measureOf(name) {
|
|
22
|
+
return name in measures ? measures[name] : pluginMeasures.get(name);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Dependency lockfiles, by exact file name. They are generated, often the largest files in a repository, and no
|
|
26
|
+
* plugin reads them: the language bar and the Metrics list give them a category of their own beside the ignored files.
|
|
27
|
+
*/
|
|
28
|
+
export const lockfileNames = new Set([
|
|
29
|
+
'package-lock.json', 'npm-shrinkwrap.json', 'yarn.lock', 'pnpm-lock.yaml', 'bun.lock', 'bun.lockb', 'deno.lock',
|
|
30
|
+
'Cargo.lock', 'Gemfile.lock', 'composer.lock', 'poetry.lock', 'Pipfile.lock', 'uv.lock', 'go.sum', 'flake.lock',
|
|
31
|
+
'mix.lock', 'pubspec.lock', 'packages.lock.json', 'gradle.lockfile',
|
|
32
|
+
]);
|
|
33
|
+
/** Whether a path names a lockfile: its file name, at any depth, exactly as the tools write it. */
|
|
34
|
+
export function isLockfile(path) {
|
|
35
|
+
return lockfileNames.has(path.slice(path.lastIndexOf('/') + 1));
|
|
36
|
+
}
|
|
37
|
+
/** Whether no plugin read a file and it is not a lockfile: what the interface calls ignored. */
|
|
38
|
+
export function isIgnored(entry) {
|
|
39
|
+
return entry.analysed === false && !isLockfile(entry.path);
|
|
40
|
+
}
|
|
41
|
+
/** The language bar's names for the two categories that are not languages. */
|
|
42
|
+
export const lockfilesLabel = 'Lockfiles';
|
|
43
|
+
export const ignoredLabel = 'Ignored';
|
|
44
|
+
/** Whether every file carries its size: inspections made before sizes were recorded carry none. */
|
|
45
|
+
export function sized(files) {
|
|
46
|
+
return files.length > 0 && files.every(entry => entry.bytes !== undefined);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* What the language bar weighs, largest language first, then lockfiles, then the ignored files. Size in bytes when
|
|
50
|
+
* every file has it: one measure for code, lockfiles and ignored files alike, untouched by formatting. Without sizes,
|
|
51
|
+
* physical lines where any file is only counted (the one line measure all files have), otherwise code lines.
|
|
52
|
+
*/
|
|
53
|
+
export function languageShares(files) {
|
|
54
|
+
const measure = sized(files) ? 'bytes'
|
|
55
|
+
: files.some(entry => entry.analysed === false || isLockfile(entry.path)) ? 'lines' : 'code-lines';
|
|
56
|
+
const weightOf = (entry) => (measure === 'bytes' ? entry.bytes
|
|
57
|
+
: measure === 'lines' ? entry.lines : entry.quality?.codeLines ?? entry.lines) ?? 0;
|
|
58
|
+
const weights = new Map();
|
|
59
|
+
let lockfiles = 0;
|
|
60
|
+
let ignored = 0;
|
|
61
|
+
for (const entry of files) {
|
|
62
|
+
if (isLockfile(entry.path))
|
|
63
|
+
lockfiles += weightOf(entry);
|
|
64
|
+
else if (entry.analysed === false)
|
|
65
|
+
ignored += weightOf(entry);
|
|
66
|
+
else {
|
|
67
|
+
const language = languageOf(entry.path);
|
|
68
|
+
weights.set(language, (weights.get(language) ?? 0) + weightOf(entry));
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
const shares = [...weights].filter(([, weight]) => weight > 0).sort((a, b) => b[1] - a[1]);
|
|
72
|
+
if (lockfiles > 0)
|
|
73
|
+
shares.push([lockfilesLabel, lockfiles]);
|
|
74
|
+
if (ignored > 0)
|
|
75
|
+
shares.push([ignoredLabel, ignored]);
|
|
76
|
+
return { measure, shares };
|
|
77
|
+
}
|
|
78
|
+
/** Ready-made conditions offered before anything is typed: the questions people ask of a codebase most. */
|
|
79
|
+
const presets = [
|
|
80
|
+
{ text: 'complexity>10', label: 'Complex functions' },
|
|
81
|
+
{ text: 'coverage<80%', label: 'Under 80% covered' },
|
|
82
|
+
{ text: 'duplication>0', label: 'Has duplication' },
|
|
83
|
+
{ text: 'remediation>0', label: 'Has technical debt' },
|
|
84
|
+
{ text: 'changes>0', label: 'Changed recently' },
|
|
85
|
+
{ text: 'has:findings', label: 'Has findings' },
|
|
86
|
+
];
|
|
87
|
+
const languages = {
|
|
88
|
+
ts: 'TypeScript', tsx: 'TypeScript', mts: 'TypeScript', cts: 'TypeScript',
|
|
89
|
+
js: 'JavaScript', jsx: 'JavaScript', mjs: 'JavaScript', cjs: 'JavaScript',
|
|
90
|
+
py: 'Python', go: 'Go', rs: 'Rust', java: 'Java', kt: 'Kotlin', kts: 'Kotlin', rb: 'Ruby', php: 'PHP', cs: 'C#',
|
|
91
|
+
c: 'C', h: 'C', cc: 'C++', cpp: 'C++', cxx: 'C++', hpp: 'C++', hh: 'C++', swift: 'Swift', scala: 'Scala',
|
|
92
|
+
vue: 'Vue', svelte: 'Svelte', sh: 'Shell', bash: 'Shell', css: 'CSS', scss: 'SCSS', less: 'Less', html: 'HTML',
|
|
93
|
+
};
|
|
94
|
+
/** Language colours follow the conventions people already know from code hosts. */
|
|
95
|
+
const languageColors = {
|
|
96
|
+
TypeScript: '#3178c6', JavaScript: '#f1e05a', Python: '#3572a5', Go: '#00add8', Rust: '#dea584', Java: '#b07219',
|
|
97
|
+
Kotlin: '#a97bff', Ruby: '#701516', PHP: '#4f5d95', 'C#': '#178600', C: '#555555', 'C++': '#f34b7d', Swift: '#f05138',
|
|
98
|
+
Scala: '#c22d40', Vue: '#41b883', Svelte: '#ff3e00', Shell: '#89e051', CSS: '#663399', SCSS: '#c6538c', Less: '#1d365d',
|
|
99
|
+
HTML: '#e34c26',
|
|
100
|
+
};
|
|
101
|
+
export function languageOf(path) {
|
|
102
|
+
const name = path.slice(path.lastIndexOf('/') + 1);
|
|
103
|
+
const dot = name.lastIndexOf('.');
|
|
104
|
+
const extension = dot > 0 ? name.slice(dot + 1).toLowerCase() : '';
|
|
105
|
+
return languages[extension] ?? (extension ? extension.toUpperCase() : 'Other');
|
|
106
|
+
}
|
|
107
|
+
export function languageColor(language) {
|
|
108
|
+
return languageColors[language] ?? 'var(--neutral-2)';
|
|
109
|
+
}
|
|
110
|
+
/** Splits the query into clauses; a word that names nothing known becomes a path fragment. */
|
|
111
|
+
export function parseQuery(text) {
|
|
112
|
+
const clauses = [];
|
|
113
|
+
for (const match of text.matchAll(/(\w+):"([^"]*)"|(\S+)/g)) {
|
|
114
|
+
const clause = match[1] ? keyed(match[1], match[2]) : parseWord(match[3]);
|
|
115
|
+
if (clause)
|
|
116
|
+
clauses.push(clause);
|
|
117
|
+
}
|
|
118
|
+
return clauses;
|
|
119
|
+
}
|
|
120
|
+
export function parseWord(word) {
|
|
121
|
+
const keyedWord = /^(\w+):(.+)$/.exec(word);
|
|
122
|
+
if (keyedWord)
|
|
123
|
+
return keyed(keyedWord[1], keyedWord[2]);
|
|
124
|
+
const condition = /^([\w.-]+)(>=|<=|>|<|=)(\d+(?:\.\d+)?)(%|h|min)?$/i.exec(word);
|
|
125
|
+
if (condition) {
|
|
126
|
+
const measure = condition[1].toLowerCase();
|
|
127
|
+
const spec = measureOf(measure);
|
|
128
|
+
if (!spec)
|
|
129
|
+
return null;
|
|
130
|
+
const number = Number(condition[3]);
|
|
131
|
+
const unit = condition[4]?.toLowerCase();
|
|
132
|
+
const value = spec.percent ? (unit === '%' || number > 1 ? number / 100 : number) : unit === 'h' ? number * 60 : number;
|
|
133
|
+
return { kind: 'measure', measure, operator: condition[2], value };
|
|
134
|
+
}
|
|
135
|
+
return word ? { kind: 'path', value: word } : null;
|
|
136
|
+
}
|
|
137
|
+
function keyed(key, value) {
|
|
138
|
+
switch (key.toLowerCase()) {
|
|
139
|
+
case 'lang':
|
|
140
|
+
case 'language': return { kind: 'lang', value };
|
|
141
|
+
case 'component': return { kind: 'component', value };
|
|
142
|
+
case 'path':
|
|
143
|
+
case 'in': return { kind: 'path', value };
|
|
144
|
+
case 'has': return value === 'findings' || value === 'diagnostics' ? { kind: 'has', value } : null;
|
|
145
|
+
// The interface and the query call the files no plugin read "ignored"; `analysed:` stays as a silent alias.
|
|
146
|
+
case 'analysed':
|
|
147
|
+
case 'analyzed': return value === 'yes' || value === 'no' ? { kind: 'analysed', value } : null;
|
|
148
|
+
case 'ignored': return value === 'yes' || value === 'no' ? { kind: 'analysed', value: value === 'yes' ? 'no' : 'yes' } : null;
|
|
149
|
+
case 'lockfile':
|
|
150
|
+
case 'lockfiles': return value === 'yes' || value === 'no' ? { kind: 'lockfile', value } : null;
|
|
151
|
+
default: return null;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
export function formatQuery(clauses) {
|
|
155
|
+
return clauses.map(clauseText).join(' ');
|
|
156
|
+
}
|
|
157
|
+
export function clauseText(clause) {
|
|
158
|
+
const quoted = (value) => /\s|"/.test(value) ? `"${value.replaceAll('"', '')}"` : value;
|
|
159
|
+
switch (clause.kind) {
|
|
160
|
+
case 'lang': return `lang:${quoted(clause.value)}`;
|
|
161
|
+
case 'component': return `component:${quoted(clause.value)}`;
|
|
162
|
+
case 'path': return /^\w+:|[<>=]/.test(clause.value) || /\s/.test(clause.value) ? `path:${quoted(clause.value)}` : clause.value;
|
|
163
|
+
case 'has': return `has:${clause.value}`;
|
|
164
|
+
case 'analysed': return `ignored:${clause.value === 'no' ? 'yes' : 'no'}`;
|
|
165
|
+
case 'lockfile': return `lockfile:${clause.value}`;
|
|
166
|
+
case 'measure': {
|
|
167
|
+
const percent = measureOf(clause.measure)?.percent;
|
|
168
|
+
const value = percent ? `${Math.round(clause.value * 1000) / 10}%` : String(clause.value);
|
|
169
|
+
return `${clause.measure}${clause.operator}${value}`;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
/** The chip's words: what it selects, in the interface's language rather than the query's. */
|
|
174
|
+
export function clauseLabel(clause) {
|
|
175
|
+
switch (clause.kind) {
|
|
176
|
+
case 'lang': return { key: 'Language', value: clause.value };
|
|
177
|
+
case 'component': return { key: 'Component', value: clause.value };
|
|
178
|
+
case 'path': return { key: 'Path', value: clause.value };
|
|
179
|
+
case 'has': return { key: 'Has', value: clause.value };
|
|
180
|
+
case 'analysed': return { key: 'Ignored', value: clause.value === 'no' ? 'Yes' : 'No' };
|
|
181
|
+
case 'lockfile': return { key: 'Lockfile', value: clause.value === 'yes' ? 'Yes' : 'No' };
|
|
182
|
+
case 'measure': {
|
|
183
|
+
const { label, percent, minutes } = measureOf(clause.measure) ?? { label: clause.measure };
|
|
184
|
+
const value = percent ? `${Math.round(clause.value * 1000) / 10}%` : minutes ? `${clause.value} min` : String(clause.value);
|
|
185
|
+
return { key: label, value: `${clause.operator === '>=' ? '≥' : clause.operator === '<=' ? '≤' : clause.operator} ${value}` };
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
export function sameClause(a, b) {
|
|
190
|
+
return clauseText(a) === clauseText(b);
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Whether a file passes the query. Chips of one kind widen the selection (TypeScript or JavaScript), chips of
|
|
194
|
+
* different kinds narrow it (TypeScript in the core component), and every condition must hold.
|
|
195
|
+
*/
|
|
196
|
+
export function matches(entry, clauses, facts, text = '') {
|
|
197
|
+
const any = (kind, test) => {
|
|
198
|
+
const values = clauses.flatMap(clause => clause.kind === kind ? [clause.value] : []);
|
|
199
|
+
return values.length === 0 || values.some(test);
|
|
200
|
+
};
|
|
201
|
+
const path = entry.path.toLowerCase();
|
|
202
|
+
if (text && !path.includes(text.toLowerCase()))
|
|
203
|
+
return false;
|
|
204
|
+
if (!any('lang', value => languageOf(entry.path).toLowerCase() === value.toLowerCase()))
|
|
205
|
+
return false;
|
|
206
|
+
if (!any('component', value => (facts.components.get(entry.path) ?? []).some(name => name.toLowerCase() === value.toLowerCase())))
|
|
207
|
+
return false;
|
|
208
|
+
if (!any('path', value => path.includes(value.toLowerCase())))
|
|
209
|
+
return false;
|
|
210
|
+
return clauses.every(clause => {
|
|
211
|
+
if (clause.kind === 'has')
|
|
212
|
+
return clause.value === 'findings' ? (facts.findings.get(entry.path) ?? 0) > 0 : entry.diagnosticCount > 0;
|
|
213
|
+
if (clause.kind === 'analysed')
|
|
214
|
+
return isIgnored(entry) === (clause.value === 'no');
|
|
215
|
+
if (clause.kind === 'lockfile')
|
|
216
|
+
return isLockfile(entry.path) === (clause.value === 'yes');
|
|
217
|
+
if (clause.kind !== 'measure')
|
|
218
|
+
return true;
|
|
219
|
+
const value = measureOf(clause.measure)?.read(entry) ?? null;
|
|
220
|
+
if (value === null)
|
|
221
|
+
return false;
|
|
222
|
+
switch (clause.operator) {
|
|
223
|
+
case '>': return value > clause.value;
|
|
224
|
+
case '>=': return value >= clause.value;
|
|
225
|
+
case '<': return value < clause.value;
|
|
226
|
+
case '<=': return value <= clause.value;
|
|
227
|
+
case '=': return value === clause.value;
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
/** What the field offers for the typed text: the facets of this codebase first, then conditions, then the path. */
|
|
232
|
+
export function suggest(text, files, facts, chosen) {
|
|
233
|
+
const query = text.trim().toLowerCase();
|
|
234
|
+
const taken = (clause) => chosen.some(other => sameClause(other, clause));
|
|
235
|
+
const result = [];
|
|
236
|
+
const counts = new Map();
|
|
237
|
+
for (const file of files)
|
|
238
|
+
counts.set(languageOf(file.path), (counts.get(languageOf(file.path)) ?? 0) + 1);
|
|
239
|
+
for (const [language, total] of [...counts].sort((a, b) => b[1] - a[1])) {
|
|
240
|
+
const clause = { kind: 'lang', value: language };
|
|
241
|
+
if (!taken(clause) && (!query || language.toLowerCase().includes(query) || 'lang'.startsWith(query))) {
|
|
242
|
+
result.push({ group: 'Languages', label: language, detail: quantity(total), clause, color: languageColor(language) });
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
const members = new Map();
|
|
246
|
+
for (const names of facts.components.values())
|
|
247
|
+
for (const name of names)
|
|
248
|
+
members.set(name, (members.get(name) ?? 0) + 1);
|
|
249
|
+
for (const [name, total] of members) {
|
|
250
|
+
const clause = { kind: 'component', value: name };
|
|
251
|
+
if (!taken(clause) && (!query || name.toLowerCase().includes(query) || 'component'.startsWith(query))) {
|
|
252
|
+
result.push({ group: 'Components', label: name, detail: quantity(total), clause });
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
// Files only counted, never read by a plugin, are one condition away once the text names them.
|
|
256
|
+
const named = (words) => query.length >= 3
|
|
257
|
+
&& words.some(phrase => phrase.startsWith(query) || (phrase.includes(' ') && phrase.includes(query)));
|
|
258
|
+
const unread = files.filter(isIgnored).length;
|
|
259
|
+
const notAnalysed = { kind: 'analysed', value: 'no' };
|
|
260
|
+
if (unread && !taken(notAnalysed) && named(['ignored files', 'ignored:yes', 'not analysed', 'analysed:no'])) {
|
|
261
|
+
result.push({ group: 'Conditions', label: 'Ignored files', detail: quantity(unread), clause: notAnalysed });
|
|
262
|
+
}
|
|
263
|
+
const lockfiles = files.filter(file => isLockfile(file.path)).length;
|
|
264
|
+
const lockfile = { kind: 'lockfile', value: 'yes' };
|
|
265
|
+
if (lockfiles && !taken(lockfile) && named(['lockfiles', 'lockfile:yes'])) {
|
|
266
|
+
result.push({ group: 'Conditions', label: lockfilesLabel, detail: quantity(lockfiles), clause: lockfile });
|
|
267
|
+
}
|
|
268
|
+
const typed = query ? parseWord(text.trim()) : null;
|
|
269
|
+
if (typed && (typed.kind === 'measure' || typed.kind === 'has' || typed.kind === 'analysed' || typed.kind === 'lockfile') && !taken(typed)) {
|
|
270
|
+
const { key, value } = clauseLabel(typed);
|
|
271
|
+
result.push({ group: 'Conditions', label: `${key} ${value}`, clause: typed });
|
|
272
|
+
}
|
|
273
|
+
else {
|
|
274
|
+
// Other plugins' metrics are offered once the typed text names them; the presets stay Repometry's own.
|
|
275
|
+
if (query)
|
|
276
|
+
for (const [key, { label }] of pluginMeasures) {
|
|
277
|
+
const clause = { kind: 'measure', measure: key, operator: '>', value: 0 };
|
|
278
|
+
if (!taken(clause) && (key.startsWith(query) || label.toLowerCase().includes(query))) {
|
|
279
|
+
result.push({ group: 'Conditions', label: `${label} above zero`, detail: `${label} > 0`, clause });
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
for (const preset of presets) {
|
|
283
|
+
const clause = parseWord(preset.text);
|
|
284
|
+
const { key, value } = clauseLabel(clause);
|
|
285
|
+
if (!taken(clause) && (!query || preset.label.toLowerCase().includes(query) || preset.text.startsWith(query) || key.toLowerCase().includes(query))) {
|
|
286
|
+
result.push({ group: 'Conditions', label: preset.label, detail: `${key} ${value}`, clause });
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
if (query && !(typed && typed.kind !== 'path')) {
|
|
291
|
+
result.push({ group: 'Path', label: `Path contains “${text.trim()}”`, clause: { kind: 'path', value: text.trim() } });
|
|
292
|
+
}
|
|
293
|
+
return result;
|
|
294
|
+
}
|
|
295
|
+
function quantity(total) {
|
|
296
|
+
return `${total.toLocaleString()} ${total === 1 ? 'file' : 'files'}`;
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* The field: chips for the chosen clauses, then a text input; the list of suggestions hangs from it in one frame.
|
|
300
|
+
* Backspace in an empty input takes the last chip back into text, so a chip can be edited, not just removed.
|
|
301
|
+
*/
|
|
302
|
+
export function queryField(clauses, options) {
|
|
303
|
+
let chosen = [...clauses];
|
|
304
|
+
let active = 0;
|
|
305
|
+
let shown = [];
|
|
306
|
+
const root = element('div', 'qf');
|
|
307
|
+
const box = element('div', 'qf-box');
|
|
308
|
+
const chips = element('span', 'qf-chips');
|
|
309
|
+
const input = element('input', 'qf-input');
|
|
310
|
+
input.type = 'text';
|
|
311
|
+
input.autocomplete = 'off';
|
|
312
|
+
input.spellcheck = false;
|
|
313
|
+
input.setAttribute('role', 'combobox');
|
|
314
|
+
input.setAttribute('aria-label', 'Filter files');
|
|
315
|
+
input.setAttribute('aria-autocomplete', 'list');
|
|
316
|
+
input.setAttribute('aria-expanded', 'false');
|
|
317
|
+
const list = element('ul', 'qf-options');
|
|
318
|
+
list.id = `qf-options-${Math.random().toString(36).slice(2, 8)}`;
|
|
319
|
+
list.setAttribute('role', 'listbox');
|
|
320
|
+
input.setAttribute('aria-controls', list.id);
|
|
321
|
+
const popover = element('div', 'qf-popover');
|
|
322
|
+
popover.hidden = true;
|
|
323
|
+
const help = element('p', 'qf-help', 'Combine chips: same kind widens, different kinds narrow. Type complexity>10 or coverage<80% for a condition.');
|
|
324
|
+
popover.append(list, help);
|
|
325
|
+
box.append(chips, input);
|
|
326
|
+
root.append(box, popover);
|
|
327
|
+
function placeholder() {
|
|
328
|
+
input.placeholder = chosen.length ? 'Add a filter' : 'Filter by language, component, condition or path';
|
|
329
|
+
}
|
|
330
|
+
function renderChips() {
|
|
331
|
+
chips.replaceChildren(...chosen.map((clause, index) => {
|
|
332
|
+
const chip = element('span', `qf-chip qf-chip-${clause.kind}`);
|
|
333
|
+
const { key, value } = clauseLabel(clause);
|
|
334
|
+
if (clause.kind === 'lang') {
|
|
335
|
+
const dot = element('span', 'qf-dot');
|
|
336
|
+
dot.style.background = languageColor(clause.value);
|
|
337
|
+
chip.append(dot);
|
|
338
|
+
}
|
|
339
|
+
chip.append(element('span', 'qf-chip-key', key), element('span', 'qf-chip-value', value));
|
|
340
|
+
const remove = element('button', 'qf-remove');
|
|
341
|
+
remove.type = 'button';
|
|
342
|
+
remove.setAttribute('aria-label', `Remove ${key} ${value}`);
|
|
343
|
+
remove.addEventListener('click', () => {
|
|
344
|
+
chosen.splice(index, 1);
|
|
345
|
+
commit();
|
|
346
|
+
input.focus();
|
|
347
|
+
});
|
|
348
|
+
chip.append(remove);
|
|
349
|
+
return chip;
|
|
350
|
+
}));
|
|
351
|
+
placeholder();
|
|
352
|
+
}
|
|
353
|
+
function commit() {
|
|
354
|
+
renderChips();
|
|
355
|
+
options.change(chosen, input.value.trim());
|
|
356
|
+
if (!popover.hidden)
|
|
357
|
+
update();
|
|
358
|
+
}
|
|
359
|
+
function update() {
|
|
360
|
+
shown = options.suggestions(input.value);
|
|
361
|
+
active = Math.min(active, Math.max(0, shown.length - 1));
|
|
362
|
+
let group = '';
|
|
363
|
+
list.replaceChildren(...shown.flatMap((suggestion, index) => {
|
|
364
|
+
const items = [];
|
|
365
|
+
if (suggestion.group !== group) {
|
|
366
|
+
group = suggestion.group;
|
|
367
|
+
const heading = element('li', 'qf-group', group);
|
|
368
|
+
heading.setAttribute('role', 'presentation');
|
|
369
|
+
items.push(heading);
|
|
370
|
+
}
|
|
371
|
+
const item = element('li', 'qf-option');
|
|
372
|
+
item.id = `${list.id}-${index}`;
|
|
373
|
+
item.setAttribute('role', 'option');
|
|
374
|
+
if (suggestion.color) {
|
|
375
|
+
const dot = element('span', 'qf-dot');
|
|
376
|
+
dot.style.background = suggestion.color;
|
|
377
|
+
item.append(dot);
|
|
378
|
+
}
|
|
379
|
+
item.append(element('span', 'qf-option-label', suggestion.label));
|
|
380
|
+
if (suggestion.detail)
|
|
381
|
+
item.append(element('span', 'qf-option-detail', suggestion.detail));
|
|
382
|
+
item.addEventListener('mousedown', event => event.preventDefault());
|
|
383
|
+
item.addEventListener('click', () => choose(suggestion));
|
|
384
|
+
item.addEventListener('mousemove', () => { if (active !== index) {
|
|
385
|
+
active = index;
|
|
386
|
+
highlight();
|
|
387
|
+
} });
|
|
388
|
+
items.push(item);
|
|
389
|
+
return items;
|
|
390
|
+
}));
|
|
391
|
+
highlight();
|
|
392
|
+
}
|
|
393
|
+
function highlight() {
|
|
394
|
+
for (const item of list.querySelectorAll('.qf-option'))
|
|
395
|
+
item.classList.toggle('active', item.id === `${list.id}-${active}`);
|
|
396
|
+
const current = list.querySelector(`#${list.id}-${active}`);
|
|
397
|
+
if (current) {
|
|
398
|
+
input.setAttribute('aria-activedescendant', current.id);
|
|
399
|
+
current.scrollIntoView({ block: 'nearest' });
|
|
400
|
+
}
|
|
401
|
+
else
|
|
402
|
+
input.removeAttribute('aria-activedescendant');
|
|
403
|
+
}
|
|
404
|
+
function open() {
|
|
405
|
+
if (!popover.hidden)
|
|
406
|
+
return;
|
|
407
|
+
popover.hidden = false;
|
|
408
|
+
root.classList.add('open');
|
|
409
|
+
input.setAttribute('aria-expanded', 'true');
|
|
410
|
+
active = 0;
|
|
411
|
+
update();
|
|
412
|
+
document.addEventListener('pointerdown', outside, true);
|
|
413
|
+
}
|
|
414
|
+
function close() {
|
|
415
|
+
if (popover.hidden)
|
|
416
|
+
return;
|
|
417
|
+
popover.hidden = true;
|
|
418
|
+
root.classList.remove('open');
|
|
419
|
+
input.setAttribute('aria-expanded', 'false');
|
|
420
|
+
document.removeEventListener('pointerdown', outside, true);
|
|
421
|
+
}
|
|
422
|
+
function outside(event) {
|
|
423
|
+
if (!root.contains(event.target))
|
|
424
|
+
close();
|
|
425
|
+
}
|
|
426
|
+
function choose(suggestion) {
|
|
427
|
+
if (!chosen.some(clause => sameClause(clause, suggestion.clause)))
|
|
428
|
+
chosen.push(suggestion.clause);
|
|
429
|
+
input.value = '';
|
|
430
|
+
active = 0;
|
|
431
|
+
commit();
|
|
432
|
+
}
|
|
433
|
+
box.addEventListener('pointerdown', event => {
|
|
434
|
+
if (event.target === box || event.target === chips) {
|
|
435
|
+
event.preventDefault();
|
|
436
|
+
input.focus();
|
|
437
|
+
}
|
|
438
|
+
});
|
|
439
|
+
input.addEventListener('focus', open);
|
|
440
|
+
input.addEventListener('input', () => {
|
|
441
|
+
open();
|
|
442
|
+
active = 0;
|
|
443
|
+
update();
|
|
444
|
+
options.change(chosen, input.value.trim());
|
|
445
|
+
});
|
|
446
|
+
input.addEventListener('keydown', event => {
|
|
447
|
+
if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
|
|
448
|
+
event.preventDefault();
|
|
449
|
+
open();
|
|
450
|
+
if (shown.length)
|
|
451
|
+
active = (active + (event.key === 'ArrowDown' ? 1 : -1) + shown.length) % shown.length;
|
|
452
|
+
highlight();
|
|
453
|
+
}
|
|
454
|
+
else if (event.key === 'Enter') {
|
|
455
|
+
event.preventDefault();
|
|
456
|
+
const typed = input.value.trim();
|
|
457
|
+
const suggestion = shown[active];
|
|
458
|
+
if (suggestion && !popover.hidden)
|
|
459
|
+
choose(suggestion);
|
|
460
|
+
else if (typed)
|
|
461
|
+
choose({ group: '', label: typed, clause: parseWord(typed) ?? { kind: 'path', value: typed } });
|
|
462
|
+
}
|
|
463
|
+
else if (event.key === 'Escape') {
|
|
464
|
+
if (!popover.hidden) {
|
|
465
|
+
event.preventDefault();
|
|
466
|
+
close();
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
else if (event.key === 'Backspace' && input.value === '' && chosen.length) {
|
|
470
|
+
event.preventDefault();
|
|
471
|
+
input.value = clauseText(chosen.pop());
|
|
472
|
+
commit();
|
|
473
|
+
}
|
|
474
|
+
});
|
|
475
|
+
renderChips();
|
|
476
|
+
return {
|
|
477
|
+
element: root,
|
|
478
|
+
text: () => input.value.trim(),
|
|
479
|
+
set(next) {
|
|
480
|
+
chosen = [...next];
|
|
481
|
+
commit();
|
|
482
|
+
},
|
|
483
|
+
};
|
|
484
|
+
}
|
|
485
|
+
function element(tag, className, text) {
|
|
486
|
+
const node = document.createElement(tag);
|
|
487
|
+
if (className)
|
|
488
|
+
node.className = className;
|
|
489
|
+
if (text !== undefined)
|
|
490
|
+
node.textContent = text;
|
|
491
|
+
return node;
|
|
492
|
+
}
|