reqtable 0.1.0__py3-none-any.whl
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.
- reqtable/__init__.py +3 -0
- reqtable/__main__.py +3 -0
- reqtable/baselines.py +920 -0
- reqtable/cli.py +631 -0
- reqtable/comparison.py +63 -0
- reqtable/core.py +1448 -0
- reqtable/drafts.py +166 -0
- reqtable/findings.py +605 -0
- reqtable/gate_checks.py +84 -0
- reqtable/gates.py +348 -0
- reqtable/glossary.py +162 -0
- reqtable/gui.py +952 -0
- reqtable/gui_lookups.py +192 -0
- reqtable/gui_mapping.py +789 -0
- reqtable/gui_page.py +691 -0
- reqtable/gui_page_gates.py +173 -0
- reqtable/gui_page_mapping.py +390 -0
- reqtable/gui_server.py +467 -0
- reqtable/html_report.py +2595 -0
- reqtable/markdown.py +127 -0
- reqtable/package.py +163 -0
- reqtable/quality.py +422 -0
- reqtable/review.py +318 -0
- reqtable/signoff.py +179 -0
- reqtable/traceability.py +1670 -0
- reqtable/values.py +192 -0
- reqtable/waivers.py +109 -0
- reqtable/xlsx.py +1108 -0
- reqtable-0.1.0.dist-info/METADATA +106 -0
- reqtable-0.1.0.dist-info/RECORD +33 -0
- reqtable-0.1.0.dist-info/WHEEL +4 -0
- reqtable-0.1.0.dist-info/entry_points.txt +2 -0
- reqtable-0.1.0.dist-info/licenses/LICENSE +21 -0
reqtable/html_report.py
ADDED
|
@@ -0,0 +1,2595 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import html
|
|
4
|
+
import json
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
from .quality import QUALITY_JS
|
|
8
|
+
from .glossary import GLOSSARY_CSS, GLOSSARY_HTML
|
|
9
|
+
from .drafts import DRAFTS_CSS, DRAFTS_HTML, DRAFTS_JS
|
|
10
|
+
from .comparison import COMPARISON_JS
|
|
11
|
+
from .gate_checks import GATE_CHECKS_JS
|
|
12
|
+
from .package import PACKAGE_CSS, PACKAGE_HTML, PACKAGE_JS
|
|
13
|
+
from .values import VALUE_EDIT_JS
|
|
14
|
+
from .traceability import (
|
|
15
|
+
TRACE_CSS,
|
|
16
|
+
TRACE_HTML,
|
|
17
|
+
TRACE_MENU,
|
|
18
|
+
TRACE_MODEL_JS,
|
|
19
|
+
TRACE_SYSTEMS,
|
|
20
|
+
TRACE_UI_JS,
|
|
21
|
+
TRACE_WORKSPACE,
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
CSS = r"""
|
|
26
|
+
:root{color-scheme:light dark;--bg:#f7f8fa;--panel:#fff;--text:#202124;--muted:#5f6368;--placeholder:#9aa0a6;--line:#d9dde3;--head:#2f3542;--headText:#fff;--accent:#0969da;--comment:#cf222e;--selected:#dbeafe;--add:#dafbe1;--addStrong:#aceebb;--remove:#ffebe9;--removeStrong:#ffcecb;--changed:#fff8c5;--shadow:0 4px 18px #0002}
|
|
27
|
+
@media(prefers-color-scheme:dark){:root{--bg:#16181d;--panel:#22252b;--text:#e6e8eb;--muted:#a8adb7;--placeholder:#7d8590;--line:#454a53;--head:#303640;--headText:#fff;--accent:#6da9ff;--comment:#ff7b72;--selected:#263b5c;--add:#173c25;--addStrong:#285c38;--remove:#4a2022;--removeStrong:#6b3033;--changed:#453f18;--shadow:0 5px 22px #0008}}
|
|
28
|
+
*{box-sizing:border-box}body{margin:0;background:var(--bg);color:var(--text);font:14px/1.45 system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif}button,input,select,textarea{font:inherit;color:var(--text);background:var(--panel)}button{cursor:pointer}.page{padding:14px 18px}.meta{color:var(--muted)}.summary{display:flex;gap:6px;flex-wrap:wrap;margin-top:5px}.summary:empty{display:none}.badge{border:1px solid var(--line);border-radius:99px;padding:2px 8px;background:var(--panel)}.badge.added{background:var(--add)}.badge.removed{background:var(--remove)}.badge.changed{background:var(--changed)}.toolbar{position:sticky;top:0;z-index:10;display:flex;gap:3px;align-items:center;flex-wrap:wrap;padding:2px 5px;border:1px solid var(--line);border-radius:7px 7px 0 0;background:var(--panel);box-shadow:0 1px 4px #0001}.toolbar .spacer{flex:1}#result-count{padding-inline-end:7px}.control,button,input,select,textarea{border:1px solid var(--line);border-radius:5px;padding:5px 8px}button:hover{border-color:var(--accent)}button[aria-pressed="true"]{background:var(--selected);border-color:var(--accent)}button:focus-visible,summary:focus-visible,input:focus-visible,select:focus-visible,textarea:focus-visible,[data-grid-cell]:focus-visible{outline:3px solid color-mix(in srgb,var(--accent),transparent 55%);outline-offset:-1px}.primary{background:var(--accent);color:#fff;border-color:var(--accent)}details{position:relative}details>summary{list-style:none;cursor:pointer;border:1px solid var(--line);border-radius:5px;padding:5px 8px}.popover{position:absolute;top:calc(100% + 5px);left:0;z-index:30;min-width:230px;max-height:80vh;overflow:auto;background:var(--panel);color:var(--text);border:1px solid var(--line);border-radius:6px;padding:10px;box-shadow:var(--shadow)}.popover label:not([hidden]){display:block;padding:4px}.table-wrap{overflow:auto;border:1px solid var(--line);border-top:0;background:var(--panel)}table{border-collapse:separate;border-spacing:0;table-layout:fixed;min-width:100%}caption{position:absolute;clip:rect(0 0 0 0)}th,td{border-right:1px solid var(--line);border-bottom:1px solid var(--line);padding:8px 10px;vertical-align:top;min-width:0;white-space:normal;overflow-wrap:anywhere}thead th{position:sticky;top:0;z-index:5;background:var(--head);color:var(--headText);text-align:left;height:37px}.heading-cell{position:sticky;padding-right:10px}.filter-row th{top:var(--heading-height,37px);height:29px;padding:2px 4px;background:var(--panel);color:var(--text)}.filter-control{position:relative}.filter-row input{display:block;width:100%;height:24px;min-width:0;padding:2px 27px 2px 6px;color:var(--text);background:var(--panel);caret-color:var(--text)}.filter-row input::placeholder{color:var(--placeholder);opacity:1}.clear-filter{position:absolute;right:1px;top:50%;transform:translateY(-50%);width:21px;height:21px;padding:0;border:0;background:transparent;color:var(--muted);font-weight:700}.clear-filter[hidden]{display:none}.sort-button{background:transparent;border:0;color:inherit;font-weight:700;padding:0;width:calc(100% - 7px);height:100%;text-align:left}.resize-handle{position:absolute;top:0;right:-4px;width:9px;height:100%;z-index:8;cursor:col-resize;touch-action:none}.resize-handle::after{content:"";position:absolute;right:3px;top:5px;bottom:5px;width:1px;background:#fff6}.resize-handle:hover::after,.resize-handle.dragging::after{width:3px;background:var(--accent)}.status-cell{position:sticky;left:0;z-index:2;background:var(--panel)}.row-added .status-cell{border-left:5px solid #1a7f37}.row-removed .status-cell{border-left:5px solid #cf222e}.row-changed .status-cell{border-left:5px solid #bf8700}[data-grid-cell].selected-cell{background:var(--selected)!important;box-shadow:inset 0 0 0 2px var(--accent)}.cell-wrap{position:relative;min-height:24px}.comment-button:not(.has-comments){opacity:0;pointer-events:none}.selected-cell .comment-button:not(.has-comments),[data-grid-cell]:hover .comment-button:not(.has-comments){opacity:1;pointer-events:auto}.comment-button.has-comments{color:var(--comment);border:1px solid var(--comment);border-radius:99px;background:var(--panel)}.markdown p{margin:0 0 .65em}.markdown p:last-child{margin-bottom:0}.markdown ul,.markdown ol{margin:.3em 0;padding-left:1.5em}.markdown pre{white-space:pre-wrap;background:#8882;padding:7px;border-radius:4px}.markdown blockquote{border-left:3px solid var(--line);margin:.4em 0;padding-left:8px;color:var(--muted)}.empty-value{color:var(--muted);font-style:italic;opacity:.5}.diff-line{white-space:pre-wrap;min-height:1.35em;margin:0 -4px;padding:1px 4px}.removed-line{background:var(--remove)}.added-line{background:var(--add)}.removed-word{background:var(--removeStrong);text-decoration:line-through}.added-word{background:var(--addStrong)}.split{display:grid;grid-template-columns:minmax(12rem,1fr) minmax(12rem,1fr);gap:4px}.pane{min-width:0;border:1px solid var(--line);border-radius:4px;overflow:hidden}.pane-label{display:block;padding:2px 5px;background:#8882;color:var(--muted);font-size:.78rem;font-weight:700}.missing{padding:5px;color:var(--muted);font-style:italic}.review-panel{position:fixed;right:0;top:0;bottom:0;z-index:50;width:min(400px,100vw);min-width:min(300px,100vw);max-width:90vw;background:var(--panel);border-left:1px solid var(--line);box-shadow:var(--shadow);display:flex;flex-direction:column}.review-panel[hidden]{display:none}.sidebar-resize{position:absolute;left:-5px;top:0;bottom:0;width:10px;cursor:col-resize;touch-action:none}.sidebar-resize:hover,.sidebar-resize.dragging{background:color-mix(in srgb,var(--accent),transparent 75%)}.review-head{display:flex;align-items:center;gap:8px;padding:12px;border-bottom:1px solid var(--line)}.review-head h2{font-size:1.1rem;margin:0;flex:1}.review-body{padding:12px;overflow:auto;flex:1}.comment-search{width:100%;margin-bottom:10px}.comment-card{border:1px solid var(--line);border-left:5px solid var(--reviewer-color,var(--line));border-radius:6px;padding:10px;margin-bottom:9px}.reviewer-chip{display:inline-block;border:1px solid var(--reviewer-color,var(--line));border-radius:99px;padding:0 5px;color:var(--text)}.comment-meta{color:var(--muted);font-size:.82rem;margin-bottom:6px}.comment-actions{display:flex;gap:6px;margin-top:8px;flex-wrap:wrap}.comment-editor textarea,.inline-comment-editor textarea{width:100%;min-height:100px;margin:7px 0;resize:vertical}.comment-editor-actions{display:flex;gap:7px}.floating-popover{position:fixed;z-index:70;width:min(380px,calc(100vw - 20px));max-height:min(520px,calc(100vh - 20px));overflow:auto;background:var(--panel);color:var(--text);border:1px solid var(--line);border-radius:7px;padding:11px;box-shadow:var(--shadow)}.floating-popover[hidden]{display:none}.floating-popover h3{margin:0 0 7px;font-size:1rem}.floating-popover textarea{width:100%;min-height:90px;resize:vertical;margin:6px 0}.quick-previous{margin-bottom:9px}.quick-previous .comment-card{margin:5px 0}.comment-tooltip{pointer-events:none;max-width:360px}.comment-tooltip .comment-card{margin:6px 0 0}.value-filter{width:min(300px,calc(100vw - 20px));max-height:300px}.value-filter label{display:block;padding:4px}.value-filter .meta{margin-bottom:5px}.value-filter .empty-option{font-style:italic}.help-dialog{width:min(650px,calc(100vw - 24px));max-height:calc(100vh - 24px);background:var(--panel);color:var(--text);border:1px solid var(--line);border-radius:8px;box-shadow:var(--shadow);padding:0}.help-dialog::backdrop{background:#0008}.help-head{display:flex;align-items:center;padding:14px;border-bottom:1px solid var(--line)}.help-head h2{margin:0;flex:1;font-size:1.2rem}.help-body{padding:14px;overflow:auto}.shortcut-table{width:100%;border-collapse:collapse}.shortcut-table th,.shortcut-table td{min-width:0;padding:6px;border:0;border-bottom:1px solid var(--line)}kbd{border:1px solid var(--line);border-bottom-width:2px;border-radius:4px;padding:1px 5px;background:var(--bg)}.notice{padding:9px;border-radius:5px;background:var(--changed);margin-bottom:10px}.empty-state{color:var(--muted);padding:20px 0}.sr-only{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0}@media(max-width:700px){.page{padding:7px}.split{grid-template-columns:1fr}.table-wrap{max-height:none}.toolbar{position:static}.review-panel{max-width:100vw}}@media print{.toolbar,.save-area,.comment-button,.review-panel,.floating-popover,.help-dialog{display:none!important}.page{padding:0}.table-wrap{max-height:none;overflow:visible;border:0}thead th,.status-cell{position:static}table{width:100%!important;table-layout:auto}th,td{font-size:9pt}}
|
|
29
|
+
.mode-badge{font-weight:700}.mode-badge.develop{color:#1a7f37;border-color:#1a7f37}.mode-badge.review{color:var(--comment);border-color:var(--comment)}.cell-editor{display:grid;gap:6px}.cell-editor textarea{width:100%;min-height:92px;resize:vertical}
|
|
30
|
+
.bool-cell{display:inline-flex;vertical-align:middle}
|
|
31
|
+
.bool-cell:not([aria-readonly]){cursor:pointer}
|
|
32
|
+
.bool-cell[aria-readonly]{opacity:.75}
|
|
33
|
+
.bool-box{position:relative;display:inline-block;width:15px;height:15px;border:1.5px solid var(--muted);border-radius:3px;background:var(--panel)}
|
|
34
|
+
.bool-cell[aria-checked="true"] .bool-box{background:var(--accent);border-color:var(--accent)}
|
|
35
|
+
.bool-cell[aria-checked="true"] .bool-box::after{content:"";position:absolute;left:4px;top:0;width:4px;height:9px;border:solid #fff;border-width:0 2px 2px 0;transform:rotate(45deg)}
|
|
36
|
+
@media print{.bool-cell[aria-checked="true"] .bool-box{background:none;border-color:#000}.bool-cell[aria-checked="true"] .bool-box::after{border-color:#000}}
|
|
37
|
+
.cell-editor-compact textarea{min-height:0;resize:none;overflow:hidden}.cell-editor-actions{display:flex;gap:6px}.progress-note{display:block;color:var(--muted);font-size:.85em}.cell-suggestions{display:grid;grid-template-columns:minmax(0,1fr);gap:0;max-height:12rem;overflow:auto;border:1px solid var(--line);border-radius:6px;padding:3px 0;background:var(--panel)}.cell-suggestions[hidden]{display:none}.cell-suggestions button{text-align:left;overflow-wrap:anywhere;border:0;border-radius:0;background:transparent;padding:4px 10px 4px 12px;box-shadow:inset 3px 0 0 transparent}.cell-suggestions button:hover{background:var(--selected)}.cell-suggestions button:focus,.cell-suggestions button:focus-visible{outline:0;background:var(--selected);box-shadow:inset 3px 0 0 var(--accent)}.cell-suggestions .suggestion-detail{display:block;color:var(--muted);font-size:.85em;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.edited-cell{position:relative}.edited-cell::before{content:"";position:absolute;left:-6px;inset-block:0;width:3px;background:#bf8700;pointer-events:none}.cell-editor-actions button{padding:0 6px;line-height:1.35;font-weight:bold}.apply-edit{color:#187439}.cancel-edit{color:#a62327}
|
|
38
|
+
.toolbar{border-inline-width:0;border-radius:0}
|
|
39
|
+
.toolbar .popup-menu>summary,.toolbar>button{padding:2px 7px}
|
|
40
|
+
.toolbar .popup-menu>summary{border-color:transparent}
|
|
41
|
+
#command-query{width:100%}
|
|
42
|
+
#command-results{display:grid;gap:2px;max-height:45vh;overflow:auto;margin-top:8px}
|
|
43
|
+
#command-results button{display:flex;justify-content:space-between;gap:12px;text-align:left}
|
|
44
|
+
#command-results small{color:var(--muted)}
|
|
45
|
+
#command-results kbd{white-space:nowrap;font:inherit;font-size:.85em}
|
|
46
|
+
.toolbar .popup-menu>summary:hover,.toolbar .popup-menu[open]>summary{background:var(--selected)}
|
|
47
|
+
.toolbar .popover{top:100%;padding:5px 0;min-width:min(17rem,calc(100vw - 20px));max-width:calc(100vw - 20px)}
|
|
48
|
+
.toolbar .popover button:not([hidden]){display:flex;align-items:center;justify-content:space-between;gap:18px;position:relative;width:100%;padding:6px 12px 6px 30px;text-align:left;border:0;border-radius:0;background:transparent}
|
|
49
|
+
.toolbar .popover button:not([hidden]){white-space:nowrap}
|
|
50
|
+
@media(max-width:600px){.toolbar .popover button:not([hidden]){white-space:normal}}
|
|
51
|
+
.toolbar .popover button:enabled:hover,.toolbar .popover button:focus-visible,.toolbar .popover label:focus-within,.toolbar .popover label:hover{background:var(--selected)}
|
|
52
|
+
.toolbar .popover button[aria-pressed="true"]::before{content:"";position:absolute;left:13px;top:50%;width:5px;height:9px;border:solid currentColor;border-width:0 2px 2px 0;transform:translateY(-62%) rotate(45deg)}
|
|
53
|
+
.toolbar .popover button:disabled{opacity:.55;cursor:default}
|
|
54
|
+
.toolbar .popover label:not([hidden]){padding:5px 12px;cursor:pointer}
|
|
55
|
+
.toolbar .popover kbd{font:inherit;font-size:.8em;color:var(--muted);white-space:nowrap;border:0;padding:0}
|
|
56
|
+
.toolbar .popover .menu-label{padding:3px 12px;color:var(--muted);font-size:.85em}
|
|
57
|
+
.toolbar .popover .compare-group{border-bottom:1px solid var(--line);margin-bottom:4px;padding-bottom:4px}
|
|
58
|
+
.comparison-line{color:var(--muted);padding-inline-end:7px}.comparison-line .warning{color:var(--comment);font-weight:600}
|
|
59
|
+
.toolbar .popover .menu-section{border-top:1px solid var(--line);margin-top:4px;padding-top:4px}
|
|
60
|
+
.toolbar .popover #hidden-filter-warning:not(:empty){padding:5px 12px}
|
|
61
|
+
.toolbar.has-active-filters {
|
|
62
|
+
background:color-mix(in srgb,var(--selected) 55%,var(--panel));
|
|
63
|
+
}
|
|
64
|
+
#active-filters {margin-inline-start:auto}
|
|
65
|
+
#active-filters>summary {display:flex; align-items:center; color:var(--accent)}
|
|
66
|
+
#active-filters[hidden] {display:none}
|
|
67
|
+
#active-filters .popover {
|
|
68
|
+
left:auto; right:0; width:max-content; min-width:0;
|
|
69
|
+
max-width:min(28rem,calc(100vw - 36px)); padding:8px 12px; overflow-wrap:anywhere;
|
|
70
|
+
}
|
|
71
|
+
#active-filter-list {display:grid; gap:4px; margin:4px 0 0; padding:0; list-style:none}
|
|
72
|
+
#active-filter-list li {display:flex; align-items:center; justify-content:space-between; gap:8px}
|
|
73
|
+
#active-filter-list .remove-filter {
|
|
74
|
+
display:flex; align-items:center; justify-content:center; flex:none;
|
|
75
|
+
width:22px; height:22px; padding:0; border:1px solid var(--line);
|
|
76
|
+
border-radius:4px; font-size:16px; line-height:1;
|
|
77
|
+
}
|
|
78
|
+
#table-context-menu{position:fixed;top:auto;left:auto;z-index:80;padding:4px;min-width:180px;max-width:calc(100vw - 16px);max-height:calc(100vh - 16px)}
|
|
79
|
+
#table-context-menu[hidden]{display:none}
|
|
80
|
+
#table-context-menu button{display:block;width:100%;text-align:left;border:0}
|
|
81
|
+
#table-context-menu button:hover,#table-context-menu button:focus-visible{background:var(--selected)}
|
|
82
|
+
.table-wrap{overflow-anchor:none;outline:none}
|
|
83
|
+
.window-spacer>td{padding:0;border:0}
|
|
84
|
+
.row-id{position:relative;font-size:.85em;font-weight:600;font-variant-numeric:tabular-nums}
|
|
85
|
+
.row-id .cell-wrap{min-height:0}
|
|
86
|
+
@media screen {
|
|
87
|
+
[data-grid-cell]:has(> .comment-button) {position:relative;padding-bottom:22px}
|
|
88
|
+
}
|
|
89
|
+
.comment-button {
|
|
90
|
+
position:absolute;right:4px;bottom:2px;min-width:20px;height:20px;
|
|
91
|
+
padding:0 3px;border:0;background:transparent;color:var(--accent);font-weight:700;line-height:1;
|
|
92
|
+
}
|
|
93
|
+
.row-with-grip{padding-inline-start:25px}
|
|
94
|
+
.row-grip{position:absolute;inset-inline-start:7px;top:8px;color:var(--muted);cursor:grab;user-select:none;touch-action:none}
|
|
95
|
+
.row-grip[aria-disabled="true"]{cursor:not-allowed;opacity:.55;touch-action:auto}
|
|
96
|
+
.compact-row-ids .row-with-grip{padding:4px 6px 8px}
|
|
97
|
+
.compact-row-ids .row-grip{position:static;display:block;width:20px;margin:0 auto 3px;line-height:16px;text-align:center}
|
|
98
|
+
[data-grid-cell].range-selected:not(.selected-cell){background:var(--selected)}
|
|
99
|
+
table.selecting{user-select:none;-webkit-user-select:none}
|
|
100
|
+
[data-grid-cell].whole-row-selected:not(.selected-cell){box-shadow:inset 0 -2px var(--accent)}
|
|
101
|
+
#row-drag-preview{position:fixed;z-index:85;pointer-events:none;width:max-content;max-width:min(280px,calc(100vw - 16px));padding:6px 10px;background:var(--panel);color:var(--text);border:1px solid var(--accent);border-radius:6px;box-shadow:var(--shadow);opacity:.88;overflow-wrap:anywhere}
|
|
102
|
+
#row-drag-preview span{display:block;font-size:.85em;color:var(--muted)}
|
|
103
|
+
tr.row-drag-source>td,tr.row-drag-source>th{background:var(--selected)}
|
|
104
|
+
tr.drop-before>td,tr.drop-before>th{box-shadow:inset 0 3px var(--accent)}
|
|
105
|
+
.order-change{display:block}.entry-row{color:var(--muted)}.filtered-empty td{padding:18px 12px;text-align:left;color:var(--muted)}.filtered-empty strong{color:var(--text,inherit)}.entry-add{padding:0 6px;line-height:1.4}.entry-hint{display:block;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
|
|
106
|
+
.cell-editor-expanded {position:fixed;z-index:65;padding:10px;background:var(--panel);border:1px solid var(--accent);border-radius:6px;box-shadow:var(--shadow);max-height:calc(100vh - 16px);overflow:auto}
|
|
107
|
+
.cell-editor-expanded textarea {resize:none}
|
|
108
|
+
.cell-editor-label {font-weight:600;overflow-wrap:anywhere}
|
|
109
|
+
#quality-panel {width:min(360px,100vw)}
|
|
110
|
+
#quality-panel .review-body > .comment-actions {margin-bottom:5px}
|
|
111
|
+
#quality-count {margin:8px 0}
|
|
112
|
+
.quality-dismissed-toggle {display:block; margin-top:5px}
|
|
113
|
+
.quality-issue {padding:6px 0; border-top:1px solid var(--line)}
|
|
114
|
+
.quality-issue:last-child {padding-bottom:0}
|
|
115
|
+
.quality-dismissed {opacity:.8}
|
|
116
|
+
#quality-settings-form label {display:block; margin-bottom:8px}
|
|
117
|
+
#quality-settings-form fieldset {border:1px solid var(--line); margin-bottom:12px}
|
|
118
|
+
#quality-dismiss-reason {display:block; width:100%; margin:6px 0}
|
|
119
|
+
.quality-card h3,.quality-dismissed h3 {font-size:1em; margin:0}
|
|
120
|
+
.quality-card,.quality-dismissed {cursor:pointer;padding-block-start:6px}
|
|
121
|
+
.quality-card-jump {background:transparent;border:0;padding:0;font-weight:700;color:var(--accent);text-align:start}
|
|
122
|
+
.quality-card-jump:hover {text-decoration:underline}
|
|
123
|
+
.quality-card p {margin:6px 0 10px}
|
|
124
|
+
.quality-card.quality-active {border-color:var(--accent); background:var(--selected)}
|
|
125
|
+
.quality-phrase {text-decoration:underline wavy var(--quality); text-underline-offset:3px}
|
|
126
|
+
.cell-wrap:has(.quality-marker) {padding-right:24px}
|
|
127
|
+
.quality-marker {
|
|
128
|
+
position:absolute; top:-4px; right:0; width:22px; height:24px;
|
|
129
|
+
border:0; padding:0; background:transparent; color:var(--quality); font-weight:700;
|
|
130
|
+
}
|
|
131
|
+
:root {--quality:#945400}
|
|
132
|
+
@media(prefers-color-scheme:dark) {:root {--quality:#ffc66b}}
|
|
133
|
+
@media screen and (min-width:901px) {
|
|
134
|
+
body:has(#quality-panel:not([hidden])) .page {margin-right:360px}
|
|
135
|
+
}
|
|
136
|
+
@media print {.quality-marker {display:none}}
|
|
137
|
+
.popover-head {display:flex;align-items:start;justify-content:space-between;gap:8px;margin-bottom:6px}
|
|
138
|
+
.popover-head h3 {margin:0}
|
|
139
|
+
.popover-close {padding:0 6px;line-height:1.2}
|
|
140
|
+
#finding-popover-list {margin:0;padding:0;list-style:none}
|
|
141
|
+
#finding-popover-list li {padding:6px 0;border-top:1px solid var(--line)}
|
|
142
|
+
.report-header {
|
|
143
|
+
display:flex; align-items:center; justify-content:space-between; flex-wrap:wrap;
|
|
144
|
+
position:relative; gap:4px 12px; margin-bottom:14px;
|
|
145
|
+
}
|
|
146
|
+
@media screen {
|
|
147
|
+
.page {padding-inline:0; padding-bottom:0}
|
|
148
|
+
.report-header,.draft-banner {margin-inline:18px}
|
|
149
|
+
.toolbar {border-radius:0}
|
|
150
|
+
}
|
|
151
|
+
.report-identity,.save-area {display:flex; align-items:center; gap:6px; min-width:0}
|
|
152
|
+
.report-identity {max-width:100%}
|
|
153
|
+
.report-identity .report-info {margin-inline-start:12px}
|
|
154
|
+
.save-area {margin-inline-start:auto}
|
|
155
|
+
.report-identity h1 {margin:0; font-size:1.3rem; overflow:hidden; text-overflow:ellipsis; white-space:nowrap}
|
|
156
|
+
.report-identity .mode-badge,.report-identity .report-info>summary {
|
|
157
|
+
flex:none; padding:1px 6px; font-size:.85em; white-space:nowrap;
|
|
158
|
+
}
|
|
159
|
+
.header-disclosure {flex:none}
|
|
160
|
+
.report-info,.dirty {position:static}
|
|
161
|
+
.header-disclosure>summary {padding:2px 6px}
|
|
162
|
+
.report-info>summary {
|
|
163
|
+
border-radius:99px; min-width:22px; text-align:center; font-weight:700;
|
|
164
|
+
color:var(--accent); border-color:var(--accent); background:var(--panel);
|
|
165
|
+
}
|
|
166
|
+
.header-disclosure>summary:hover,.header-disclosure[open]>summary {background:var(--selected)}
|
|
167
|
+
.header-disclosure .popover {
|
|
168
|
+
z-index:35; width:max-content; min-width:0; max-width:min(34rem,calc(100vw - 36px));
|
|
169
|
+
overflow-wrap:anywhere;
|
|
170
|
+
}
|
|
171
|
+
.save-area .popover {left:auto; right:0}
|
|
172
|
+
#reviewer-initials {display:block; width:10rem; margin-top:4px}
|
|
173
|
+
#reviewer-label {display:inline-block; max-width:9rem; overflow:hidden; text-overflow:ellipsis; vertical-align:bottom; white-space:nowrap}
|
|
174
|
+
.dirty>summary {color:#b54708; font-weight:700}
|
|
175
|
+
#save-status {flex-basis:100%; overflow-wrap:anywhere}
|
|
176
|
+
#save-status:empty,.print-details {display:none}
|
|
177
|
+
@media screen and (min-width:701px) {
|
|
178
|
+
.page {height:100vh; display:flex; flex-direction:column}
|
|
179
|
+
.report-header,.toolbar,.draft-banner {flex:none}
|
|
180
|
+
.table-wrap {min-height:0}
|
|
181
|
+
}
|
|
182
|
+
@media screen and (max-width:700px) {
|
|
183
|
+
.report-header,.draft-banner {margin-inline:7px}
|
|
184
|
+
.report-header {margin-bottom:7px}
|
|
185
|
+
.report-identity .report-info {margin-inline-start:1px}
|
|
186
|
+
}
|
|
187
|
+
@media print {
|
|
188
|
+
.report-header .header-disclosure,#save-status {display:none}
|
|
189
|
+
.report-identity h1 {white-space:normal; overflow:visible}
|
|
190
|
+
.print-details {display:block; flex-basis:100%}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
"""
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
JS = (
|
|
197
|
+
r"""
|
|
198
|
+
"use strict";
|
|
199
|
+
const data=JSON.parse(document.getElementById("reqtable-data").textContent);
|
|
200
|
+
function configuredPixels(column,fallback=column.estimatedWidth||160){const raw=column.width;if(!raw)return fallback;const n=parseFloat(raw);if(raw.endsWith("rem")||raw.endsWith("em"))return n*16;if(raw.endsWith("ch"))return n*8;if(raw.endsWith("%"))return Math.max(70,document.documentElement.clientWidth*n/100);return n;}
|
|
201
|
+
const cloneValue=value=>JSON.parse(JSON.stringify(value));
|
|
202
|
+
const state={hidden:new Set(data.columns.filter(c=>c.hidden).map(c=>c.name)),filters:new Map(),valueFilters:new Map(),statuses:new Set(["added","removed","changed","unchanged"]),commentsOnly:false,idFilter:null,view:data.options.initialView,sort:null,comments:cloneValue(data.comments),savedComments:cloneValue(data.comments),currentRows:cloneValue(data.source.new.rows),savedRows:cloneValue(data.source.new.rows),dirty:false,requirementsDirty:false,commentsDirty:false,compareWith:data.meta.mode==="diff"?"old":null,undo:[],redo:[],editingCell:null,commentContext:null,editingId:null,widths:new Map(data.columns.map(c=>[c.name,configuredPixels(c)])),focus:{row:0,column:0}};
|
|
203
|
+
state.qualityReview=cloneValue(data.qualityReview??{settings:data.options.quality??{},dismissals:[]});
|
|
204
|
+
state.decisions=cloneValue(data.decisions??[]);state.savedDecisions=cloneValue(state.decisions);
|
|
205
|
+
{const key=data.options.initialCompareWith;if(key&&key!==state.compareWith&&(key==="old"?data.source.old:baselineByKey(key)))setCompareWith(key);if(data.package)state.statuses=new Set(["added","removed","changed","unchanged"]);}
|
|
206
|
+
state.savedQualityReview=cloneValue(state.qualityReview);
|
|
207
|
+
if(data.meta.mode==="diff"&&data.options.initialChangesOnly)state.statuses.delete("unchanged");
|
|
208
|
+
const grid={display:[],start:0,end:0,heights:new Map(),offsets:new Float64Array(1),columns:0,canDrag:false,comments:new Map(),layouts:new Map(),layoutKey:"",stale:false,printing:false,frame:0,filteredEmpty:false};
|
|
209
|
+
const $=s=>document.querySelector(s),table=$("#requirements-table"),tableBody=$("#requirements-body"),headRow=$("#heading-row"),filterRow=$("#filter-row"),resultCount=$("#result-count"),quick=$("#quick-comment"),hover=$("#comment-hover"),valuePopover=$("#value-filter-popover"),review=$("#review-panel"),help=$("#keyboard-help");
|
|
210
|
+
const findingPopover=createFindingPopover();
|
|
211
|
+
if(window.ResizeObserver)new ResizeObserver(()=>table.style.setProperty("--heading-height",`${headRow.getBoundingClientRect().height}px`)).observe(headRow);
|
|
212
|
+
function rowElement(index){return tableBody.querySelector(`tr[data-row-index="${index}"]`);}
|
|
213
|
+
function cellElement(row,column){return rowElement(row)?.querySelector(`[data-column-index="${column}"]`)??null;}
|
|
214
|
+
function cellPosition(cell){return {row:+cell.dataset.rowIndex,column:+cell.dataset.columnIndex};}
|
|
215
|
+
function displayIndex(id){return grid.display.findIndex(row=>row.id===id);}
|
|
216
|
+
function escapeHtml(s){return String(s).replace(/[&<>"']/g,c=>({"&":"&","<":"<",">":">",'"':""","'":"'"}[c]));}
|
|
217
|
+
function commentInline(text){
|
|
218
|
+
const pattern=/`([^`\n]+)`|\[([^\]\n]+)\]\(([^)\n]+)\)|\*\*([^*\n]+)\*\*|__([^_\n]+)__|(?<!\*)\*([^*\n]+)\*(?!\*)|(?<!_)_([^_\n]+)_(?!_)/g;
|
|
219
|
+
let result="",end=0;
|
|
220
|
+
for(const match of text.matchAll(pattern)){
|
|
221
|
+
const [source,code,label,target,strong,underline,em,italic]=match;
|
|
222
|
+
result+=escapeHtml(text.slice(end,match.index));
|
|
223
|
+
if(code!==undefined)result+=`<code>${escapeHtml(code)}</code>`;
|
|
224
|
+
else if(label!==undefined){
|
|
225
|
+
const url=target.trim();
|
|
226
|
+
result+=/^(?:https?:\/\/|mailto:)/i.test(url)?`<a href="${escapeHtml(url)}">${escapeHtml(label)}</a>`:`${escapeHtml(label)} (${escapeHtml(url)})`;
|
|
227
|
+
}else if(strong!==undefined||underline!==undefined)result+=`<strong>${escapeHtml(strong??underline)}</strong>`;
|
|
228
|
+
else result+=`<em>${escapeHtml(em??italic)}</em>`;
|
|
229
|
+
end=match.index+source.length;
|
|
230
|
+
}
|
|
231
|
+
return result+escapeHtml(text.slice(end));
|
|
232
|
+
}
|
|
233
|
+
function renderCommentMarkdown(s){const lines=String(s).split("\n"),out=[];let para=[],list=null,quote=[],code=null;const flushPara=()=>{if(para.length){out.push(`<p>${para.map(commentInline).join("<br>")}</p>`);para=[];}},closeList=()=>{if(list){out.push(`</${list}>`);list=null;}},flushQuote=()=>{if(quote.length){out.push(`<blockquote>${quote.map(commentInline).join("<br>")}</blockquote>`);quote=[];}};for(const line of lines){if(code){if(line.startsWith("```")){out.push(`<pre><code>${escapeHtml(code.join("\n"))}</code></pre>`);code=null;}else code.push(line);continue;}if(line.startsWith("```")){flushPara();closeList();flushQuote();code=[];continue;}const h=line.match(/^(#{1,6})\s+(.+)$/);if(h){flushPara();closeList();flushQuote();const level=Math.min(6,h[1].length+2);out.push(`<h${level}>${commentInline(h[2])}</h${level}>`);continue;}const item=line.match(/^\s*[-+*]\s+(.+)$/),ordered=line.match(/^\s*\d+[.)]\s+(.+)$/);if(item||ordered){flushPara();flushQuote();const wanted=item?"ul":"ol";if(list!==wanted){closeList();out.push(`<${wanted}>`);list=wanted;}out.push(`<li>${commentInline((item||ordered)[1])}</li>`);continue;}if(line.startsWith(">")){flushPara();closeList();quote.push(line.slice(1).trimStart());continue;}if(!line.trim()){flushPara();closeList();flushQuote();}else{closeList();flushQuote();para.push(line);}}if(code)out.push(`<pre><code>${escapeHtml(code.join("\n"))}</code></pre>`);flushPara();closeList();flushQuote();return out.join("");}
|
|
234
|
+
function localTimestamp(){const d=new Date(),off=-d.getTimezoneOffset(),sign=off>=0?"+":"-",pad=n=>String(Math.abs(n)).padStart(2,"0");return `${d.getFullYear()}-${pad(d.getMonth()+1)}-${pad(d.getDate())}T${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}${sign}${pad(Math.trunc(Math.abs(off)/60))}:${pad(Math.abs(off)%60)}`;}
|
|
235
|
+
function displayTimestamp(value){const d=new Date(value);if(Number.isNaN(d.getTime()))return value;const pad=n=>String(n).padStart(2,"0");return `${d.getFullYear()}-${pad(d.getMonth()+1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}`;}
|
|
236
|
+
function filenameTimestamp(){const d=new Date(),pad=n=>String(n).padStart(2,"0");return `${d.getFullYear()}${pad(d.getMonth()+1)}${pad(d.getDate())}-${pad(d.getHours())}${pad(d.getMinutes())}${pad(d.getSeconds())}`;}
|
|
237
|
+
function reviewerColor(initials){let hash=0;for(const ch of initials.toLocaleUpperCase())hash=(hash*31+ch.codePointAt(0))>>>0;return `hsl(${hash%360} 68% 48%)`;}
|
|
238
|
+
function availableColumns(){return trace?data.columns.filter(c=>trace.columnAvailable(c.name)).sort((a,b)=>trace.columnRank(a.name)-trace.columnRank(b.name)):data.columns;}
|
|
239
|
+
function columnLabel(name){return data.columns.find(column=>column.name===name)?.label??name;}
|
|
240
|
+
function visibleColumns(){return availableColumns().filter(c=>!state.hidden.has(c.name));}
|
|
241
|
+
function defaultHiddenColumns(){return trace?.defaultHidden()??new Set(data.columns.filter(c=>c.hidden).map(c=>c.name));}
|
|
242
|
+
function valueFor(row,col){const cell=row.cells[col];return(cell.new===null?cell.old:cell.new)??"";}function commentsFor(rid,column){return state.comments.filter(c=>c.requirementId===rid&&c.column===column);}
|
|
243
|
+
function commentKey(rid,column){return `${rid}\u0000${column}`;}
|
|
244
|
+
function indexComments(){grid.comments=new Map();for(const c of state.comments){const key=commentKey(c.requirementId,c.column);grid.comments.set(key,(grid.comments.get(key)??0)+1);}}
|
|
245
|
+
|
|
246
|
+
function sortedRows(){const rows=data.rows.filter(matches);if(!state.sort)return rows.sort((a,b)=>a.sourceOrder-b.sourceOrder);const{column,direction}=state.sort;return rows.sort((a,b)=>{const av=valueFor(a,column),bv=valueFor(b,column);if(!av&&!bv)return a.sourceOrder-b.sourceOrder;if(!av)return 1;if(!bv)return-1;const cmp=naturalCompare(av,bv);return(cmp||a.sourceOrder-b.sourceOrder)*direction;});}
|
|
247
|
+
function commentCard(c,actions=""){const stamp=displayTimestamp(c.modified||c.created);return `<article class="comment-card" style="--reviewer-color:${reviewerColor(c.initials)}"><div class="comment-meta"><strong class="reviewer-chip">${escapeHtml(c.initials)}</strong> · ${escapeHtml(stamp)}${c.modified?' (edited)':''}<br>${escapeHtml(c.requirementId)} · ${escapeHtml(c.column)}</div><div class="markdown">${renderCommentMarkdown(c.text)}</div>${actions}</article>`;}
|
|
248
|
+
|
|
249
|
+
function dataCell(row,column,ri,ci,{canDrag,focus,bounds,wholeRows,firstColumn}){
|
|
250
|
+
const isId=column.name===data.meta.idColumn,tag=isId?"th":"td";
|
|
251
|
+
const grip=isId&&row.id&&developMode();
|
|
252
|
+
const focused=focus.row===ri&&focus.column===ci;
|
|
253
|
+
const ranged=!!bounds&&ri>=bounds.top&&ri<=bounds.bottom&&ci>=bounds.left&&ci<=bounds.right;
|
|
254
|
+
const classes=[isId&&row.id&&"row-id",grip&&"row-with-grip",focused&&"selected-cell",ranged&&"range-selected",ranged&&wholeRows&&"whole-row-selected"].filter(Boolean).join(" ");
|
|
255
|
+
const attributes=(isId?' scope="row" role="rowheader"':' role="gridcell"')+(classes?` class="${classes}"`:"")
|
|
256
|
+
+` aria-colindex="${firstColumn+ci}" aria-selected="${focused||ranged}"`;
|
|
257
|
+
const marker=isId?trace?.rowMarker(row.id)??"":"";
|
|
258
|
+
return `<${tag}${attributes} tabindex="${focused?0:-1}" data-grid-cell data-row-index="${ri}" data-column-index="${ci}" data-column="${escapeHtml(column.name)}">${grip?rowGrip(canDrag):""}${renderCell(row,column)}${marker}</${tag}>`;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
function rowGrip(enabled){
|
|
262
|
+
const title=enabled?"Drag to reorder requirement":"Reordering needs the normal view in source order with no filters";
|
|
263
|
+
return `<span class="row-grip" aria-disabled="${!enabled}" title="${title}" aria-hidden="true">⠿</span>`;
|
|
264
|
+
}
|
|
265
|
+
function canDragRows(){
|
|
266
|
+
return developMode()&&!diffActive()&&!state.sort&&!state.commentsOnly&&!state.idFilter
|
|
267
|
+
&&!quality.only&&!trace?.scoped()&&state.statuses.has("unchanged")&&!data.columns.some(column=>filterActive(column.name));
|
|
268
|
+
}
|
|
269
|
+
function renderHead(){const cols=visibleColumns();headRow.innerHTML=statusHead()+cols.map((c,i)=>`<th scope="col" role="columnheader" aria-colindex="${firstDataColumn()+i}" class="heading-cell" data-header-column="${escapeHtml(c.name)}"><button class="sort-button" data-sort="${escapeHtml(c.name)}">${escapeHtml(c.label)} <span aria-hidden="true">${state.sort&&state.sort.column===c.name?(state.sort.direction===1?'▲':'▼'):''}</span></button><span class="resize-handle" data-resize="${escapeHtml(c.name)}" role="separator" aria-orientation="vertical" aria-label="Resize ${escapeHtml(c.label)} column" title="Drag to resize; double-click to auto-size"></span></th>`).join("");filterRow.innerHTML=statusFilterHead()+cols.map((c,i)=>{const value=state.filters.get(c.name)||'',selected=state.valueFilters.get(c.name),active=value||selected?.size;return `<th role="gridcell" aria-colindex="${firstDataColumn()+i}"><label class="sr-only" for="filter-${escapeHtml(c.name)}">Filter ${escapeHtml(c.label)}</label><div class="filter-control"><input id="filter-${escapeHtml(c.name)}" data-filter="${escapeHtml(c.name)}" value="${escapeHtml(value)}" placeholder="${selected?.size?`${selected.size} selected`:'Filter…'}"><button class="clear-filter" data-clear-filter="${escapeHtml(c.name)}" aria-label="Clear ${escapeHtml(c.label)} filter" ${active?'':'hidden'}>×</button></div></th>`;}).join("");}
|
|
270
|
+
let rangeSelection=null;
|
|
271
|
+
function selectionBounds(){
|
|
272
|
+
const {anchor,extent,wholeRows}=rangeSelection??{anchor:state.focus,extent:state.focus,wholeRows:false};
|
|
273
|
+
return {
|
|
274
|
+
top:Math.min(anchor.row,extent.row),bottom:Math.max(anchor.row,extent.row),
|
|
275
|
+
left:wholeRows?0:Math.min(anchor.column,extent.column),
|
|
276
|
+
right:wholeRows?visibleColumns().length-1:Math.max(anchor.column,extent.column)
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
let paintedRange=null,selectedCell=null;
|
|
280
|
+
function currentRange(){return rangeSelection?{...selectionBounds(),wholeRows:rangeSelection.wholeRows}:null;}
|
|
281
|
+
function paintRange(range,on){
|
|
282
|
+
for(let row=Math.max(range.top,grid.start);row<=Math.min(range.bottom,grid.end-1);row++){
|
|
283
|
+
for(const cell of rowElement(row)?.querySelectorAll("[data-grid-cell]")??[]){
|
|
284
|
+
const column=+cell.dataset.columnIndex;
|
|
285
|
+
if(column<range.left||column>range.right)continue;
|
|
286
|
+
cell.classList.toggle("range-selected",on);
|
|
287
|
+
cell.classList.toggle("whole-row-selected",on&&range.wholeRows);
|
|
288
|
+
syncAriaSelected(cell);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
function syncAriaSelected(cell){
|
|
293
|
+
cell.setAttribute("aria-selected",cell.classList.contains("selected-cell")||cell.classList.contains("range-selected"));
|
|
294
|
+
}
|
|
295
|
+
function paintSelection(){
|
|
296
|
+
if(paintedRange)paintRange(paintedRange,false);
|
|
297
|
+
paintedRange=currentRange();
|
|
298
|
+
if(paintedRange)paintRange(paintedRange,true);
|
|
299
|
+
}
|
|
300
|
+
function extendSelection(position){
|
|
301
|
+
rangeSelection={anchor:rangeSelection?.anchor??{...state.focus},
|
|
302
|
+
extent:{...position},
|
|
303
|
+
wholeRows:rangeSelection?.wholeRows??false};
|
|
304
|
+
focusGridCell(rangeSelection.extent.row,rangeSelection.extent.column,true);
|
|
305
|
+
}
|
|
306
|
+
function setRovingFocus(){
|
|
307
|
+
const previous=selectedCell?.isConnected?selectedCell:tableBody.querySelector(".selected-cell");
|
|
308
|
+
if(previous){previous.tabIndex=-1;previous.classList.remove("selected-cell");syncAriaSelected(previous);}
|
|
309
|
+
selectedCell=null;
|
|
310
|
+
const shown=grid.display.length>0;
|
|
311
|
+
if(shown){
|
|
312
|
+
state.focus={row:Math.max(0,Math.min(state.focus.row,grid.display.length-1)),column:Math.max(0,Math.min(state.focus.column,visibleColumns().length-1))};
|
|
313
|
+
selectedCell=cellElement(state.focus.row,state.focus.column);
|
|
314
|
+
if(selectedCell){selectedCell.tabIndex=0;selectedCell.classList.add("selected-cell");syncAriaSelected(selectedCell);}
|
|
315
|
+
}
|
|
316
|
+
const focused=shown?grid.display[state.focus.row]:null,row=focused?.id?focused:undefined;
|
|
317
|
+
const column=shown?visibleColumns()[state.focus.column]?.name:undefined;
|
|
318
|
+
$("#revert-selected-cell").disabled=!!state.editingCell||!canRevertCell(column,row?.cells[column]);
|
|
319
|
+
const current=row?.id&&row.status!=="removed";
|
|
320
|
+
$("#delete-record-label").textContent=`Delete ${recordKind(current?row.cells.Type?.new:null)}`;
|
|
321
|
+
$("#delete-requirement").disabled=!current||!!state.editingCell||!!trace?.pageView();
|
|
322
|
+
$("#restore-deleted-requirement").textContent=`Restore deleted ${recordKind(row?.cells.Type?.old)}`;
|
|
323
|
+
paintSelection();
|
|
324
|
+
trace?.syncSelection(row?.id??null);
|
|
325
|
+
$("#restore-deleted-requirement").disabled=!!state.editingCell||!developMode()||row?.status!=="removed";
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+
function showIdFilter(label,ids){state.idFilter={label,ids:new Set(ids)};}function filterActive(column){return Boolean(state.filters.get(column)||state.valueFilters.get(column)?.size);}function renderColumnChooser(){const box=$("#column-list");box.innerHTML=availableColumns().map(c=>`<label><input type="checkbox" data-column-toggle="${escapeHtml(c.name)}" ${state.hidden.has(c.name)?'':'checked'}> ${escapeHtml(c.label)}</label>`).join("");const hiddenFiltered=data.columns.filter(c=>state.hidden.has(c.name)&&filterActive(c.name)).length;$("#hidden-filter-warning").textContent=hiddenFiltered?`${hiddenFiltered} hidden column filter${hiddenFiltered===1?' is':'s are'} active`:"";}function renderStatusControls(){document.querySelectorAll("[data-status]").forEach(el=>el.checked=state.statuses.has(el.dataset.status));}function cycleSort(column){if(!state.sort||state.sort.column!==column)state.sort={column,direction:1};else if(state.sort.direction===1)state.sort.direction=-1;else state.sort=null;render();}
|
|
330
|
+
function renderActiveFilters(){
|
|
331
|
+
const details=$("#active-filters"),summary=details.querySelector("summary");
|
|
332
|
+
const filters=trace?.filters()??[];
|
|
333
|
+
for(const column of data.columns){
|
|
334
|
+
if(!filterActive(column.name))continue;
|
|
335
|
+
const label=column.label+(state.hidden.has(column.name)?" (hidden column)":"");
|
|
336
|
+
const query=state.filters.get(column.name),values=state.valueFilters.get(column.name);
|
|
337
|
+
if(query)filters.push([`${label} contains “${query}”`,()=>state.filters.delete(column.name)]);
|
|
338
|
+
if(values?.size)filters.push([
|
|
339
|
+
`${label} is ${[...values].map(valueFilterLabel).join(" or ")}`,
|
|
340
|
+
()=>state.valueFilters.delete(column.name)
|
|
341
|
+
]);
|
|
342
|
+
}
|
|
343
|
+
if(quality.only)filters.push(["Rows with quality findings",()=>{quality.only=false;}]);
|
|
344
|
+
if(state.commentsOnly)filters.push(["Rows with comments only",()=>{state.commentsOnly=false;}]);
|
|
345
|
+
if(state.idFilter)filters.push([state.idFilter.label,()=>{state.idFilter=null;}]);
|
|
346
|
+
if(diffActive()){
|
|
347
|
+
const statuses=["added","removed","changed","unchanged"];
|
|
348
|
+
const available=statuses.filter(status=>status!=="unchanged"||state.compareWith!=="old"||data.options.includeUnchanged);
|
|
349
|
+
const shown=available.filter(status=>state.statuses.has(status));
|
|
350
|
+
if(shown.length<available.length){
|
|
351
|
+
filters.push([shown.length?`Status: ${shown.join(", ")}`:"Status: no statuses selected",
|
|
352
|
+
()=>{state.statuses=new Set(statuses);}]);
|
|
353
|
+
}
|
|
354
|
+
if(available.length<statuses.length)filters.push([quality.revealId===null?"This report excludes unchanged rows":"Unchanged rows are excluded except for the revealed requirement"]);
|
|
355
|
+
}
|
|
356
|
+
const active=filters.length>0&&!trace?.pageView();
|
|
357
|
+
details.closest(".toolbar").classList.toggle("has-active-filters",active);
|
|
358
|
+
details.hidden=!active;
|
|
359
|
+
if(!active)details.open=false;
|
|
360
|
+
summary.title=filters.map(([description])=>description).join("\n");
|
|
361
|
+
summary.setAttribute("aria-label",`Active filters (${filters.length})`);
|
|
362
|
+
const list=$("#active-filter-list");
|
|
363
|
+
list.replaceChildren(...filters.map(([description,remove],index)=>{
|
|
364
|
+
const item=document.createElement("li");
|
|
365
|
+
const label=document.createElement("span");
|
|
366
|
+
label.textContent=description;
|
|
367
|
+
item.append(label);
|
|
368
|
+
if(remove){
|
|
369
|
+
const button=document.createElement("button");
|
|
370
|
+
button.type="button";
|
|
371
|
+
button.className="remove-filter";
|
|
372
|
+
button.textContent="×";
|
|
373
|
+
button.setAttribute("aria-label",`Remove filter: ${description}`);
|
|
374
|
+
button.addEventListener("click",event=>{
|
|
375
|
+
event.stopPropagation();
|
|
376
|
+
remove();
|
|
377
|
+
render();
|
|
378
|
+
const next=list.children[index]?.querySelector("button")??list.querySelector("button");
|
|
379
|
+
(next??(details.hidden?$("#clear-filters").closest("details").querySelector("summary"):summary)).focus();
|
|
380
|
+
});
|
|
381
|
+
item.append(button);
|
|
382
|
+
}
|
|
383
|
+
return item;
|
|
384
|
+
}));
|
|
385
|
+
return active?filters.filter(([,remove])=>remove).length:0;
|
|
386
|
+
}
|
|
387
|
+
function clearAllFilters(){
|
|
388
|
+
state.filters.clear();state.valueFilters.clear();state.commentsOnly=false;state.idFilter=null;quality.only=false;
|
|
389
|
+
state.statuses=new Set(["added","removed","changed","unchanged"]);trace?.reset();
|
|
390
|
+
}
|
|
391
|
+
function closeHeaderPopups(except=null){document.querySelectorAll("details.popup-menu[open]").forEach(d=>{if(d!==except)d.removeAttribute("open");});}function closeQuick(){quick.hidden=true;quick.innerHTML="";state.editingId=null;}function sameReviewer(c){return c&&c.initials.toLocaleUpperCase()===reviewerInitials().toLocaleUpperCase()&&Boolean(reviewerInitials());}
|
|
392
|
+
function openQuick(button){hover.hidden=true;closeHeaderPopups();const cell=button.closest("[data-grid-cell]");if(cell){state.focus={row:+cell.dataset.rowIndex,column:+cell.dataset.columnIndex};setRovingFocus();}const rid=button.dataset.commentRow,column=button.dataset.commentColumn,existing=commentsFor(rid,column).sort((a,b)=>a.created.localeCompare(b.created)),previous=existing[existing.length-1];state.commentContext={rid,column};state.editingId=null;const previousHtml=previous?`<div class="quick-previous"><div class="meta">Previous comment${existing.length>1?` · ${existing.length-1} earlier`:''}</div>${commentCard(previous,sameReviewer(previous)?`<div class="comment-actions"><button type="button" data-quick-edit-comment="${escapeHtml(previous.id)}">Edit</button></div>`:"")}</div>`:"";quick.innerHTML=`<h3>${escapeHtml(rid)} / ${escapeHtml(column)}</h3>${previousHtml}<form id="quick-comment-form"><label for="quick-comment-text">New comment</label><textarea id="quick-comment-text" required></textarea><div class="comment-actions"><button class="primary" id="quick-comment-save" type="submit">Add comment</button><button type="button" id="open-comment-sidebar">Show sidebar</button><button type="button" id="close-quick-comment">Cancel</button></div></form>`;positionPopover(quick,button);$("#quick-comment-form").addEventListener("submit",saveQuickComment);$("#open-comment-sidebar").addEventListener("click",()=>{closeQuick();openComments(rid,column,true);});$("#close-quick-comment").addEventListener("click",()=>{closeQuick();restoreSelectedCell();});$("#quick-comment-text").focus();}
|
|
393
|
+
function addComment(text,rid,column){if(column===data.meta.idColumn){alert("Comments cannot be attached to the ID column.");return false;}const initials=reviewerInitials();if(!validInitials(initials)){alert("Enter 1–16 reviewer initials without control characters.");focusReviewerInitials();return false;}persistReviewerInitials();if(developMode())remember();state.comments.push({id:(globalThis.crypto&&crypto.randomUUID?crypto.randomUUID():`${Date.now()}-${Math.random()}`),requirementId:rid,column,initials,created:localTimestamp(),modified:null,text});setDirty(true);return true;}
|
|
394
|
+
function saveQuickComment(e){e.preventDefault();const text=$("#quick-comment-text").value.trim();if(!text)return;if(state.editingId){const c=state.comments.find(x=>x.id===state.editingId);if(!sameReviewer(c)){alert("Only the same reviewer can edit this comment from the quick view.");return;}if(developMode())remember();c.text=text;c.modified=localTimestamp();setDirty(true);}else if(!addComment(text,state.commentContext.rid,state.commentContext.column))return;closeQuick();render();restoreSelectedCell();}
|
|
395
|
+
function showCommentHover(button){if(!button.classList.contains("has-comments")||!quick.hidden)return;const list=commentsFor(button.dataset.commentRow,button.dataset.commentColumn);hover.innerHTML=`<strong>${escapeHtml(button.dataset.commentRow)} / ${escapeHtml(button.dataset.commentColumn)}</strong>`+list.map(c=>commentCard(c)).join("");positionPopover(hover,button);}function hideCommentHover(){hover.hidden=true;hover.innerHTML="";}
|
|
396
|
+
function showValueFilter(input){const column=input.dataset.filter,selected=state.valueFilters.get(column)||new Set(),{blank,listed:values}=valueFilterOptions(data.rows.map(r=>valueFor(r,column))),empty=blank||selected.has(EMPTY_FILTER);if(values.length+(empty?1:0)<2||values.length>50){valuePopover.hidden=true;return;}const box=(value,label,cls)=>`<label${cls}><input type="checkbox" data-value-filter="${escapeHtml(column)}" value="${escapeHtml(value)}" ${selected.has(value)?'checked':''}> ${label}</label>`;valuePopover.innerHTML=`<div class="meta">Select ${escapeHtml(column)} values</div>`+(empty?box(EMPTY_FILTER,"(Empty)",' class="empty-option"'):"")+values.map(v=>box(v,escapeHtml(v),"")).join("");positionPopover(valuePopover,input);}function closeValueFilter(){valuePopover.hidden=true;valuePopover.innerHTML="";}
|
|
397
|
+
let resize=null,sidebarResize=null;document.addEventListener("pointerdown",e=>{const sidebar=e.target.closest("[data-sidebar-resize]");if(sidebar){e.preventDefault();sidebarResize={handle:sidebar};sidebar.classList.add("dragging");sidebar.setPointerCapture?.(e.pointerId);return;}const handle=e.target.closest("[data-resize]");if(!handle)return;e.preventDefault();freezeColumnWidths();resize={column:handle.dataset.resize,startX:e.clientX,startWidth:handle.parentElement.getBoundingClientRect().width,handle};handle.classList.add("dragging");handle.setPointerCapture?.(e.pointerId);});document.addEventListener("pointermove",e=>{if(sidebarResize){review.style.width=`${Math.max(300,Math.min(innerWidth*.9,innerWidth-e.clientX))}px`;return;}if(!resize)return;setColumnWidth(resize.column,Math.max(70,Math.min(Math.max(900,resize.startWidth),resize.startWidth+e.clientX-resize.startX)));renderLayout();});document.addEventListener("pointerup",()=>{if(resize)resize.handle.classList.remove("dragging");if(sidebarResize)sidebarResize.handle.classList.remove("dragging");resize=null;sidebarResize=null;});function autoSizeColumn(column){const values=grid.display.filter(r=>r.id!=="").slice(0,1000).map(r=>valueFor(r,column)),label=data.columns.find(c=>c.name===column).label,lengths=[label,...values.flatMap(v=>String(v).split("\n"))].map(s=>s.length).sort((a,b)=>a-b),p=lengths[Math.floor((lengths.length-1)*.95)]||label.length;setColumnWidth(column,Math.max(82,Math.min(640,34+p*7)));renderLayout();}document.addEventListener("dblclick",e=>{const handle=e.target.closest("[data-resize]");if(handle){e.preventDefault();e.stopPropagation();autoSizeColumn(handle.dataset.resize);}});
|
|
398
|
+
document.addEventListener("click",e=>{const quickEdit=e.target.closest("[data-quick-edit-comment]");if(quickEdit){const c=state.comments.find(x=>x.id===quickEdit.dataset.quickEditComment);if(c&&sameReviewer(c)){state.editingId=c.id;$("#quick-comment-text").value=c.text;$("#quick-comment-form label").textContent="Edit previous comment";$("#quick-comment-save").textContent="Save changes";$("#quick-comment-text").focus();}return;}const handle=e.target.closest("[data-resize],[data-sidebar-resize]");if(handle){e.preventDefault();return;}const clear=e.target.closest("[data-clear-filter]");if(clear){const column=clear.dataset.clearFilter;state.filters.delete(column);state.valueFilters.delete(column);closeValueFilter();renderHead();renderBodyOnly();requestAnimationFrame(()=>{const input=[...document.querySelectorAll("[data-filter]")].find(x=>x.dataset.filter===column);if(input){input.focus();showValueFilter(input);}});return;}const sort=e.target.closest("[data-sort]");if(sort){cycleSort(sort.dataset.sort);return;}const comment=e.target.closest("[data-comment-row]");if(comment){openQuick(comment);return;}const edit=e.target.closest("[data-edit-comment]");if(edit){state.editingId=edit.dataset.editComment;renderReviewPanel(true);return;}const del=e.target.closest("[data-delete-comment]");if(del){deleteComment(del.dataset.deleteComment);return;}const nav=e.target.closest("[data-go-comment]");if(nav){const c=state.comments.find(x=>x.id===nav.dataset.goComment);if(c)goToComment(c);return;}const cell=e.target.closest("[data-grid-cell]");if(cell){state.focus={row:+cell.dataset.rowIndex,column:+cell.dataset.columnIndex};setRovingFocus();}if(!e.target.closest("#quick-comment"))closeQuick();if(!e.target.closest("#value-filter-popover")&&!e.target.matches("[data-filter]"))closeValueFilter();});
|
|
399
|
+
document.addEventListener("mouseover",e=>{const button=e.target.closest(".comment-button.has-comments");if(button)showCommentHover(button);});document.addEventListener("mouseout",e=>{const button=e.target.closest(".comment-button.has-comments");if(button&&!button.contains(e.relatedTarget))hideCommentHover();});document.addEventListener("focusin",e=>{const cell=e.target.closest("[data-grid-cell]");if(cell){state.focus={row:+cell.dataset.rowIndex,column:+cell.dataset.columnIndex};setRovingFocus();}const button=e.target.closest(".comment-button.has-comments");if(button)showCommentHover(button);if(e.target.matches("[data-filter]"))showValueFilter(e.target);});document.addEventListener("focusout",e=>{const button=e.target.closest(".comment-button.has-comments");if(button)hideCommentHover();});
|
|
400
|
+
let filterTimer=null;document.addEventListener("input",e=>{if(e.target.matches("[data-cell-editor] textarea")&&state.editingCell){
|
|
401
|
+
state.editingCell.draft=e.target.value;
|
|
402
|
+
updateCellSuggestions(e.target.form);
|
|
403
|
+
}if(e.target.matches("[data-filter]")){const column=e.target.dataset.filter;state.valueFilters.delete(column);state.filters.set(column,e.target.value.toLocaleLowerCase());const clear=e.target.parentElement.querySelector("[data-clear-filter]");if(clear)clear.hidden=!e.target.value;clearTimeout(filterTimer);filterTimer=setTimeout(renderBodyOnly,100);showValueFilter(e.target);}if(e.target.id==="comment-search")renderReviewPanel();if(e.target.id==="reviewer-initials"){persistReviewerInitials();syncReviewerLabel();}});
|
|
404
|
+
document.addEventListener("change",e=>{if(e.target.matches("[data-column-toggle]")){
|
|
405
|
+
const column=e.target.dataset.columnToggle,hadFocus=e.target===document.activeElement;
|
|
406
|
+
e.target.checked?state.hidden.delete(column):state.hidden.add(column);
|
|
407
|
+
render();
|
|
408
|
+
if(hadFocus){
|
|
409
|
+
[...document.querySelectorAll("[data-column-toggle]")].find(input=>input.dataset.columnToggle===column)?.focus();
|
|
410
|
+
}
|
|
411
|
+
}if(e.target.matches("[data-status]")){e.target.checked?state.statuses.add(e.target.dataset.status):state.statuses.delete(e.target.dataset.status);render();}if(e.target.matches("[data-value-filter]")){const column=e.target.dataset.valueFilter,chosen=new Set([...valuePopover.querySelectorAll("[data-value-filter]")].filter(x=>x.checked).map(x=>x.value));if(chosen.size)state.valueFilters.set(column,chosen);else state.valueFilters.delete(column);state.filters.delete(column);renderHead();renderBodyOnly();requestAnimationFrame(()=>{const input=[...document.querySelectorAll("[data-filter]")].find(x=>x.dataset.filter===column);if(input)showValueFilter(input);});}});
|
|
412
|
+
$("#view-toggle").addEventListener("click",()=>{state.view=state.view==="unified"?"side-by-side":"unified";render();});$("#changes-only").addEventListener("click",()=>{state.statuses=new Set(["added","removed","changed"]);render();});$("#comments-only-rows").addEventListener("click",()=>{state.commentsOnly=!state.commentsOnly;renderBodyOnly();});$("#clear-filters").addEventListener("click",()=>{clearAllFilters();render();});tableBody.addEventListener("click",e=>{if(e.target.closest("[data-clear-filters]")){clearAllFilters();render();}});$("#reset-view").addEventListener("click",()=>{state.hidden=defaultHiddenColumns();state.filters.clear();state.valueFilters.clear();state.commentsOnly=false;state.idFilter=null;state.statuses=new Set(["added","removed","changed","unchanged"]);quality.only=false;quality.revealId=null;trace?.reset();state.view=data.options.initialView;state.sort=null;resetColumnWidths();render();});$("#show-all-columns").addEventListener("click",()=>{state.hidden.clear();closeHeaderPopups();render();});$("#default-columns").addEventListener("click",()=>{state.hidden=defaultHiddenColumns();closeHeaderPopups();render();});document.querySelectorAll("details.popup-menu").forEach(details=>details.addEventListener("toggle",()=>{if(details.open)closeHeaderPopups(details);}));
|
|
413
|
+
$("#browse-comments").addEventListener("click",()=>{if(!review.hidden){closeReview();return;}showAllComments(true);});$("#close-review").addEventListener("click",closeReview);$("#back-comments").addEventListener("click",()=>showAllComments(true));function closeReview(){review.hidden=true;$("#browse-comments").setAttribute("aria-expanded","false");}function resetReviewFilters(){$("#reviewer-filter").value="";$("#comment-column-filter").value="";$("#comment-status-filter").value="";populateReviewFilters();}
|
|
414
|
+
function populateReviewFilters(){const setOptions=(el,values,label)=>{const current=el.value;el.innerHTML=`<option value="">${label}</option>`+[...values].sort().map(v=>`<option value="${escapeHtml(v)}">${escapeHtml(v)}</option>`).join("");el.value=current;};setOptions($("#reviewer-filter"),new Set(state.comments.map(c=>c.initials)),"All reviewers");setOptions($("#comment-column-filter"),new Set(data.columns.filter(c=>c.name!==data.meta.idColumn).map(c=>c.name)),"All columns");}
|
|
415
|
+
function showAllComments(focusSearch=false){trace?.close();closeQuality();state.commentContext=null;state.editingId=null;review.hidden=false;$("#browse-comments").setAttribute("aria-expanded","true");renderReviewPanel();if(focusSearch)requestAnimationFrame(()=>$("#comment-search").focus());}function openComments(rid,column,focusEditor=false){if(column===data.meta.idColumn)return;trace?.close();closeQuality();state.commentContext={rid,column};state.editingId=null;$("#comment-search").value="";resetReviewFilters();review.hidden=false;$("#browse-comments").setAttribute("aria-expanded","true");renderReviewPanel(focusEditor);}
|
|
416
|
+
function renderReviewPanel(focusEditor=false){populateReviewFilters();const reviewBody=$(".review-body"),previousScroll=reviewBody.scrollTop,context=state.commentContext,q=($("#comment-search").value||"").toLocaleLowerCase(),reviewer=$("#reviewer-filter").value,column=$("#comment-column-filter").value,status=$("#comment-status-filter").value,statusMap=new Map(data.rows.map(r=>[r.id,r.status]));let list=state.comments.filter(c=>!context||(c.requirementId===context.rid&&c.column===context.column));list=list.filter(c=>(!reviewer||c.initials===reviewer)&&(!column||c.column===column)&&(!status||statusMap.get(c.requirementId)===status)&&`${c.text}\n${c.initials}\n${c.requirementId}\n${c.column}\n${c.created}\n${c.modified||''}`.toLocaleLowerCase().includes(q)).sort((a,b)=>a.created.localeCompare(b.created));const cellCount=new Set(state.comments.map(c=>`${c.requirementId}\u0000${c.column}`)).size;$("#review-title").textContent=context?`Comments: ${context.rid} / ${context.column}`:"All comments";$("#back-comments").hidden=!context;$("#comment-counts").textContent=`${state.comments.length} comments across ${cellCount} cells · ${list.length} shown`;let body=list.map(c=>c.id===state.editingId?`<article class="comment-card" style="--reviewer-color:${reviewerColor(c.initials)}"><div class="comment-meta"><strong class="reviewer-chip">${escapeHtml(c.initials)}</strong> · ${escapeHtml(displayTimestamp(c.modified||c.created))}${c.modified?' (edited)':''}<br>${escapeHtml(c.requirementId)} · ${escapeHtml(c.column)}</div><form class="inline-comment-editor" data-inline-comment-id="${escapeHtml(c.id)}"><label class="sr-only" for="inline-comment-text-${escapeHtml(c.id)}">Edit comment</label><textarea id="inline-comment-text-${escapeHtml(c.id)}" required>${escapeHtml(c.text)}</textarea><div class="comment-editor-actions"><button class="primary" type="submit">Save changes</button><button type="button" data-cancel-inline-edit>Cancel</button></div></form></article>`:commentCard(c,`<div class="comment-actions"><button data-go-comment="${escapeHtml(c.id)}">Go to cell</button><button data-edit-comment="${escapeHtml(c.id)}">Edit</button><button data-delete-comment="${escapeHtml(c.id)}">Delete</button></div>`)).join("");if(!list.length)body='<div class="empty-state">No comments match.</div>';const editor=context&&!state.editingId?`<form id="comment-form" class="comment-editor"><label for="comment-text">New comment</label><textarea id="comment-text" required></textarea><div class="comment-editor-actions"><button class="primary" type="submit">Add comment</button></div></form>`:"";$("#comment-list").innerHTML=body+editor;reviewBody.scrollTop=previousScroll;const form=$("#comment-form");if(form)form.addEventListener("submit",saveComment);document.querySelectorAll(".inline-comment-editor").forEach(el=>el.addEventListener("submit",saveInlineComment));document.querySelectorAll("[data-cancel-inline-edit]").forEach(el=>el.addEventListener("click",cancelInlineEdit));if(focusEditor)requestAnimationFrame(()=>$(".inline-comment-editor textarea,#comment-text")?.focus());}
|
|
417
|
+
function reviewerInitials(){return $("#reviewer-initials").value.trim();}function validInitials(s){return s.length>=1&&s.length<=16&&![...s].some(c=>c.charCodeAt(0)<32||c.charCodeAt(0)===127);}function loadReviewerInitials(){try{return localStorage.getItem("reqtable-reviewer-initials")||"";}catch{return "";}}function persistReviewerInitials(){const initials=reviewerInitials();if(!validInitials(initials))return;try{localStorage.setItem("reqtable-reviewer-initials",initials);}catch{}}
|
|
418
|
+
function restoreSidebarFocus(id){requestAnimationFrame(()=>{const button=[...document.querySelectorAll("[data-edit-comment]")].find(x=>x.dataset.editComment===id);(button||$("#comment-search"))?.focus();});}function cancelInlineEdit(){const id=state.editingId;state.editingId=null;renderReviewPanel();restoreSidebarFocus(id);}function saveInlineComment(e){e.preventDefault();const id=e.currentTarget.dataset.inlineCommentId,c=state.comments.find(x=>x.id===id),text=e.currentTarget.querySelector("textarea").value.trim(),initials=reviewerInitials();if(!c||!text)return;if(!validInitials(initials)){alert("Enter 1–16 reviewer initials without control characters.");return;}if(developMode())remember();c.text=text;c.initials=initials;c.modified=localTimestamp();state.editingId=null;persistReviewerInitials();setDirty(true);render();renderReviewPanel();restoreSidebarFocus(id);}function saveComment(e){e.preventDefault();const text=$("#comment-text").value.trim();if(!text||!state.commentContext)return;if(!addComment(text,state.commentContext.rid,state.commentContext.column))return;render();renderReviewPanel();restoreSelectedCell();}function deleteComment(id){if(!confirm("Delete this comment?"))return;if(developMode())remember();state.comments=state.comments.filter(c=>c.id!==id);setDirty(true);render();renderReviewPanel();restoreSelectedCell();}
|
|
419
|
+
function goToComment(c){if(state.compareWith===null&&data.source.old&&!findCurrentRow(c.requirementId))setCompareWith("old");trace?.reveal(c.requirementId,c.column);state.hidden.delete(c.column);state.filters.clear();state.valueFilters.clear();state.commentsOnly=false;state.idFilter=null;state.statuses=new Set(["added","removed","changed","unchanged"]);render();requestAnimationFrame(()=>{const row=displayIndex(c.requirementId),column=visibleColumns().findIndex(x=>x.name===c.column);if(row>=0&&column>=0)focusGridCell(row,column);});}
|
|
420
|
+
function safeJson(value){return JSON.stringify(value).replace(/</g,"\\u003c").replace(/>/g,"\\u003e").replace(/&/g,"\\u0026").replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029");}function filenameInitials(s){return s.replace(/[^A-Za-z0-9_-]+/g,"-").replace(/^[-_]+|[-_]+$/g,"");}
|
|
421
|
+
function downloadBlob(blob,filename){const url=URL.createObjectURL(blob),a=document.createElement("a");a.href=url;a.download=filename;document.body.appendChild(a);a.click();a.remove();setTimeout(()=>URL.revokeObjectURL(url),1000);}
|
|
422
|
+
function showHelp(){closeHeaderPopups();closeQuick();if(typeof help.showModal==="function")help.showModal();else help.setAttribute("open","");}$("#show-help").addEventListener("click",showHelp);$("#close-help").addEventListener("click",()=>help.close());
|
|
423
|
+
|
|
424
|
+
function focusGridCell(row,column,keepRange=false){if(!keepRange)rangeSelection=null;if(!grid.display.length)return;row=Math.max(0,Math.min(grid.display.length-1,row));column=Math.max(0,Math.min(visibleColumns().length-1,column));revealRow(row);const cell=cellElement(row,column);if(cell){state.focus={row,column};setRovingFocus();cell.focus({preventScroll:true});ensureCellVisible(cell);}}function restoreSelectedCell(){requestAnimationFrame(()=>focusGridCell(state.focus.row,state.focus.column));}function focusSelectedFilter(){const column=visibleColumns()[state.focus.column],input=column&&[...document.querySelectorAll("[data-filter]")].find(x=>x.dataset.filter===column.name);if(input){input.focus();input.select();}}function enterTableFromFilter(input){const column=visibleColumns().findIndex(c=>c.name===input.dataset.filter);clearTimeout(filterTimer);closeValueFilter();renderBodyOnly();requestAnimationFrame(()=>focusGridCell(0,Math.max(0,column)));}
|
|
425
|
+
const arrowSteps={
|
|
426
|
+
ArrowLeft:[0,-1],ArrowRight:[0,1],ArrowUp:[-1,0],ArrowDown:[1,0]
|
|
427
|
+
};
|
|
428
|
+
const keyboardMode=$("#keyboard-mode");
|
|
429
|
+
function vimKeys(){return !developMode()||keyboardMode.value==="vim";}
|
|
430
|
+
const appleKeyboard=/Mac|iPhone|iPad|iPod/.test(navigator.platform);
|
|
431
|
+
function syncKeyboardShortcuts(){
|
|
432
|
+
const glyphs={Mod:appleKeyboard?"⌘":"Ctrl+",Alt:appleKeyboard?"⌥":"Alt+",Shift:appleKeyboard?"⇧":"Shift+",Backspace:"⌫",Delete:"⌦"};
|
|
433
|
+
document.querySelectorAll("[data-shortcut]").forEach(hint=>{
|
|
434
|
+
const keys=vimKeys()&&hint.hasAttribute("data-vim-shortcut")?hint.dataset.vimShortcut:hint.dataset.shortcut;
|
|
435
|
+
hint.hidden=!keys;
|
|
436
|
+
hint.textContent=keys.split(" ").map(key=>glyphs[key]??key).join("");
|
|
437
|
+
});
|
|
438
|
+
}
|
|
439
|
+
keyboardMode.addEventListener("change",()=>{
|
|
440
|
+
pendingG=null;
|
|
441
|
+
syncKeyboardShortcuts();
|
|
442
|
+
});
|
|
443
|
+
syncKeyboardShortcuts();
|
|
444
|
+
function tabNeighbor({row,column},backward){
|
|
445
|
+
const last=visibleColumns().length-1;
|
|
446
|
+
column+=backward?-1:1;
|
|
447
|
+
if(column<0){row--;column=last;}
|
|
448
|
+
else if(column>last){row++;column=0;}
|
|
449
|
+
return row>=0&&row<grid.display.length?{row,column}:null;
|
|
450
|
+
}
|
|
451
|
+
let pendingG=null;
|
|
452
|
+
function jumpGridRegion(row,column,dr,dc){
|
|
453
|
+
const rows=grid.display,columns=visibleColumns();
|
|
454
|
+
const inGrid=(r,c)=>r>=0&&r<rows.length&&c>=0&&c<columns.length;
|
|
455
|
+
const filled=(r,c)=>Boolean(rows[r]&&valueFor(rows[r],columns[c].name).trim());
|
|
456
|
+
if(!inGrid(row+dr,column+dc))return;
|
|
457
|
+
const followRun=filled(row,column)&&filled(row+dr,column+dc);
|
|
458
|
+
while(inGrid(row+dr,column+dc)){
|
|
459
|
+
const nextFilled=filled(row+dr,column+dc);
|
|
460
|
+
if(followRun&&!nextFilled)break;
|
|
461
|
+
row+=dr;
|
|
462
|
+
column+=dc;
|
|
463
|
+
if(!followRun&&nextFilled)break;
|
|
464
|
+
}
|
|
465
|
+
focusGridCell(row,column);
|
|
466
|
+
}
|
|
467
|
+
document.addEventListener("focusout",e=>{
|
|
468
|
+
if(e.target===pendingG)pendingG=null;
|
|
469
|
+
});
|
|
470
|
+
document.addEventListener("keydown",e=>{
|
|
471
|
+
const previousG=pendingG;
|
|
472
|
+
pendingG=null;
|
|
473
|
+
if(e.defaultPrevented||e.isComposing)return;
|
|
474
|
+
if(e.key==="Escape"){
|
|
475
|
+
closeHeaderPopups();closeQuick();closeValueFilter();hideCommentHover();closeReview();closeQuality();trace?.close();restoreSelectedCell();
|
|
476
|
+
return;
|
|
477
|
+
}
|
|
478
|
+
if(e.target.matches("[data-filter]")&&(e.key==="ArrowDown"||e.key==="Enter")){
|
|
479
|
+
e.preventDefault();
|
|
480
|
+
enterTableFromFilter(e.target);
|
|
481
|
+
return;
|
|
482
|
+
}
|
|
483
|
+
if(e.target.matches("input,textarea,select")||e.target.isContentEditable)return;
|
|
484
|
+
const modified=e.ctrlKey||e.metaKey;
|
|
485
|
+
if(!modified&&!e.altKey&&e.key==="?"){e.preventDefault();showHelp();return;}
|
|
486
|
+
if(!modified&&!e.altKey&&e.key==="/"){
|
|
487
|
+
e.preventDefault();
|
|
488
|
+
if(!review.hidden&&!state.commentContext){$("#comment-search").focus();$("#comment-search").select();}
|
|
489
|
+
else focusSelectedFilter();
|
|
490
|
+
return;
|
|
491
|
+
}
|
|
492
|
+
const cell=e.target.closest("[data-grid-cell]");
|
|
493
|
+
if(!cell)return;
|
|
494
|
+
let row=+cell.dataset.rowIndex,column=+cell.dataset.columnIndex;
|
|
495
|
+
const develop=developMode(),vim=vimKeys(),key=e.key.toLowerCase(),step=Object.hasOwn(arrowSteps,e.key)&&arrowSteps[e.key];
|
|
496
|
+
const lastColumn=visibleColumns().length-1;
|
|
497
|
+
if(develop&&!vim&&e.target===cell&&!state.editingCell&&handleSpreadsheetRowShortcut(e))return;
|
|
498
|
+
if(!state.editingCell&&e.target===cell&&e.shiftKey&&!modified&&!e.altKey&&step){
|
|
499
|
+
e.preventDefault();
|
|
500
|
+
const target={row:row+step[0],column:column+step[1]};
|
|
501
|
+
if(target.row>=0&&target.row<grid.display.length&&target.column>=0&&target.column<=lastColumn)extendSelection(target);
|
|
502
|
+
return;
|
|
503
|
+
}
|
|
504
|
+
if(e.altKey)return;
|
|
505
|
+
if(modified){
|
|
506
|
+
if(e.shiftKey)return;
|
|
507
|
+
if(develop&&step&&e.target===cell){
|
|
508
|
+
e.preventDefault();
|
|
509
|
+
jumpGridRegion(row,column,...step);
|
|
510
|
+
return;
|
|
511
|
+
}
|
|
512
|
+
if(e.key!=="Home"&&e.key!=="End")return;
|
|
513
|
+
if(!develop&&!e.ctrlKey)return;
|
|
514
|
+
row=e.key==="Home"?0:develop?grid.display.findLastIndex(item=>item.id!==""):Number.MAX_SAFE_INTEGER;
|
|
515
|
+
column=e.key==="Home"?0:lastColumn;
|
|
516
|
+
}else if(develop&&e.key==="Tab"&&e.target===cell){
|
|
517
|
+
const next=tabNeighbor({row,column},e.shiftKey);
|
|
518
|
+
if(!next)return;
|
|
519
|
+
({row,column}=next);
|
|
520
|
+
}else if(step){
|
|
521
|
+
row+=step[0];
|
|
522
|
+
column+=step[1];
|
|
523
|
+
}else if(vim&&key==="h")column--;
|
|
524
|
+
else if(vim&&key==="l")column++;
|
|
525
|
+
else if(vim&&key==="k")row--;
|
|
526
|
+
else if(vim&&key==="j")row++;
|
|
527
|
+
else if(e.key==="Home"||(vim&&e.key==="0"))column=0;
|
|
528
|
+
else if(e.key==="End"||(vim&&e.key==="$"))column=lastColumn;
|
|
529
|
+
else if(e.key==="PageUp")row-=10;
|
|
530
|
+
else if(e.key==="PageDown")row+=10;
|
|
531
|
+
else if(vim&&key==="g"){
|
|
532
|
+
if(develop&&!e.shiftKey){
|
|
533
|
+
e.preventDefault();
|
|
534
|
+
if(e.repeat||previousG!==cell){pendingG=cell;return;}
|
|
535
|
+
}
|
|
536
|
+
row=e.shiftKey?Number.MAX_SAFE_INTEGER:0;
|
|
537
|
+
}else if(develop&&(vim&&key==="i")&&e.target===cell){
|
|
538
|
+
e.preventDefault();
|
|
539
|
+
startCellEdit(cell);
|
|
540
|
+
return;
|
|
541
|
+
}else if(develop&&(vim&&key==="o")&&e.target===cell&&!state.editingCell){
|
|
542
|
+
e.preventDefault();
|
|
543
|
+
if(!e.repeat)addRequirement(e.shiftKey?"above":"below");
|
|
544
|
+
return;
|
|
545
|
+
}else if((e.key==="Enter"||(vim&&key==="c"))&&data.options.commentsEnabled&&cell.dataset.column!==data.meta.idColumn){
|
|
546
|
+
if(e.key==="Enter"&&e.target!==cell)return;
|
|
547
|
+
e.preventDefault();
|
|
548
|
+
cell.querySelector(".comment-button")?.click();
|
|
549
|
+
return;
|
|
550
|
+
}else if(develop&&!vim&&e.target===cell&&[...e.key].length===1){
|
|
551
|
+
if(startCellEdit(cell,{initialText:e.key}))e.preventDefault();
|
|
552
|
+
return;
|
|
553
|
+
}else return;
|
|
554
|
+
e.preventDefault();
|
|
555
|
+
focusGridCell(row,column);
|
|
556
|
+
});
|
|
557
|
+
document.querySelectorAll("#reviewer-filter,#comment-column-filter,#comment-status-filter").forEach(el=>el.addEventListener("change",renderReviewPanel));if(data.meta.mode!=="diff")document.querySelectorAll(".diff-only").forEach(el=>el.hidden=true);if(!data.options.commentsEnabled)document.querySelectorAll(".comments-only").forEach(el=>el.hidden=true);const storedInitials=loadReviewerInitials();if(storedInitials)$("#reviewer-initials").value=storedInitials;syncReviewerLabel();populateReviewFilters();
|
|
558
|
+
|
|
559
|
+
/* Develop-mode editing and browser-side persistence. */
|
|
560
|
+
function developMode(){return data.meta.documentMode==="develop";}function diffActive(){return state.compareWith!==null;}function rowId(row){return String(row[data.meta.idColumn]??"").trim();}function byId(rows){return new Map(rows.map(row=>[rowId(row),row]));}
|
|
561
|
+
function wordChanges(a,b){
|
|
562
|
+
const removed=new Set(),added=new Set();
|
|
563
|
+
if(!a.length||!b.length||a.length*b.length>20000)return [removed,added];
|
|
564
|
+
const dp=Array.from({length:a.length+1},()=>new Uint32Array(b.length+1));
|
|
565
|
+
for(let i=a.length-1;i>=0;i--)for(let j=b.length-1;j>=0;j--){
|
|
566
|
+
dp[i][j]=a[i]===b[j]?dp[i+1][j+1]+1:Math.max(dp[i+1][j],dp[i][j+1]);
|
|
567
|
+
}
|
|
568
|
+
let i=0,j=0;
|
|
569
|
+
while(i<a.length||j<b.length){
|
|
570
|
+
if(i<a.length&&j<b.length&&a[i]===b[j]){i++;j++;}
|
|
571
|
+
else if(j>=b.length||(i<a.length&&dp[i+1][j]>=dp[i][j+1]))removed.add(i++);
|
|
572
|
+
else added.add(j++);
|
|
573
|
+
}
|
|
574
|
+
return [removed,added];
|
|
575
|
+
}
|
|
576
|
+
const diffTokens=/\s+|[\p{L}\p{N}_]+|[^\p{L}\p{N}_\s]/gu;
|
|
577
|
+
function highlightToken(token,changed,kind){
|
|
578
|
+
const text=escapeHtml(token);
|
|
579
|
+
return changed&&token.trim()?`<span class="diff-word ${kind}-word">${text}</span>`:text;
|
|
580
|
+
}
|
|
581
|
+
function diffWords(oldText,newText){
|
|
582
|
+
const left=oldText.match(diffTokens)??[],right=newText.match(diffTokens)??[];
|
|
583
|
+
const [removed,added]=wordChanges(left,right);
|
|
584
|
+
return [left.map((token,i)=>highlightToken(token,removed.has(i),"removed")).join(""),
|
|
585
|
+
right.map((token,i)=>highlightToken(token,added.has(i),"added")).join("")];
|
|
586
|
+
}
|
|
587
|
+
function markdownDiff(oldText,newText){
|
|
588
|
+
function parse(text){
|
|
589
|
+
const template=document.createElement("template");
|
|
590
|
+
template.innerHTML=renderCommentMarkdown(text);
|
|
591
|
+
const walker=document.createTreeWalker(template.content,NodeFilter.SHOW_TEXT);
|
|
592
|
+
const tokens=[],nodes=[];
|
|
593
|
+
for(let node=walker.nextNode();node;node=walker.nextNode()){
|
|
594
|
+
const words=node.data.match(diffTokens)??[];
|
|
595
|
+
nodes.push({node,start:tokens.length,words});
|
|
596
|
+
tokens.push(...words);
|
|
597
|
+
}
|
|
598
|
+
return {template,tokens,nodes};
|
|
599
|
+
}
|
|
600
|
+
function highlight(side,changed,kind){
|
|
601
|
+
if(!side.template.innerHTML)return "";
|
|
602
|
+
const fragment=document.createElement("template");
|
|
603
|
+
for(const {node,start,words} of side.nodes){
|
|
604
|
+
if(!words.some((_,i)=>changed.has(start+i)))continue;
|
|
605
|
+
fragment.innerHTML=words.map((token,i)=>highlightToken(token,changed.has(start+i),kind)).join("");
|
|
606
|
+
node.replaceWith(fragment.content);
|
|
607
|
+
}
|
|
608
|
+
return `<div class="diff-line ${kind}-line">${side.template.innerHTML}</div>`;
|
|
609
|
+
}
|
|
610
|
+
const left=parse(oldText),right=parse(newText);
|
|
611
|
+
const [removed,added]=wordChanges(left.tokens,right.tokens);
|
|
612
|
+
const oldHtml=highlight(left,removed,"removed"),newHtml=highlight(right,added,"added");
|
|
613
|
+
return {oldHtml,newHtml,unifiedHtml:oldHtml+newHtml};
|
|
614
|
+
}
|
|
615
|
+
function browserDiff(oldText,newText){oldText=String(oldText);newText=String(newText);if(!oldText&&newText){const h=newText.split("\n").map(x=>`<div class="diff-line added-line">${escapeHtml(x)||" "}</div>`).join("");return{oldHtml:"",newHtml:h,unifiedHtml:h};}if(oldText&&!newText){const h=oldText.split("\n").map(x=>`<div class="diff-line removed-line">${escapeHtml(x)||" "}</div>`).join("");return{oldHtml:h,newHtml:"",unifiedHtml:h};}const a=oldText.split("\n"),b=newText.split("\n"),count=Math.max(a.length,b.length),oldParts=[],newParts=[],unified=[];for(let i=0;i<count;i++){if(i>=a.length){const h=`<div class="diff-line added-line">${escapeHtml(b[i])||" "}</div>`;newParts.push(h);unified.push(h);}else if(i>=b.length){const h=`<div class="diff-line removed-line">${escapeHtml(a[i])||" "}</div>`;oldParts.push(h);unified.push(h);}else if(a[i]===b[i]){const h=`<div class="diff-line context-line">${escapeHtml(a[i])||" "}</div>`;oldParts.push(h);newParts.push(h);unified.push(h);}else{const pair=diffWords(a[i],b[i]),oh=`<div class="diff-line removed-line">${pair[0]||" "}</div>`,nh=`<div class="diff-line added-line">${pair[1]||" "}</div>`;oldParts.push(oh);newParts.push(nh);unified.push(oh,nh);}}return{oldHtml:oldParts.join(""),newHtml:newParts.join(""),unifiedHtml:unified.join("")};}
|
|
616
|
+
function renderRequirementValue(value,column){value=String(value??"");if(!value)return'<span class="empty-value">Empty</span>';return column.markdown?renderCommentMarkdown(value):escapeHtml(value).replace(/\n/g,"<br>");}function comparisonValue(value){return data.options.ignoreTrailingWhitespace?value.split("\n").map(line=>line.trimEnd()).join("\n"):value;}
|
|
617
|
+
function runtimeCell(column,oldValue,newValue,source){
|
|
618
|
+
const oldText=oldValue??"",newText=newValue??"";
|
|
619
|
+
const changed=Boolean(source)&&!source.ignoredColumns.has(column.name)&&comparisonValue(oldText)!==comparisonValue(newText);
|
|
620
|
+
const progress=!changed&&!!source?.progressColumns?.has(column.name)&&oldValue!==null&&newValue!==null&&comparisonValue(oldText)!==comparisonValue(newText);
|
|
621
|
+
return {column:column.name,old:oldValue,new:newValue,changed,progress,search:`${oldText}\n${newText}`.toLocaleLowerCase(),html:null};
|
|
622
|
+
}
|
|
623
|
+
function cellHtml(cell,column,part){
|
|
624
|
+
cell.html??={};
|
|
625
|
+
if(cell.html[part]!==undefined)return cell.html[part];
|
|
626
|
+
const oldText=cell.old??"",newText=cell.new??"";
|
|
627
|
+
if(cell.changed)Object.assign(cell.html,column.markdown?markdownDiff(oldText,newText):browserDiff(oldText,newText));
|
|
628
|
+
else if(part==="oldHtml")cell.html.oldHtml=renderRequirementValue(oldText,column);
|
|
629
|
+
else if(part==="newHtml")cell.html.newHtml=renderRequirementValue(newText,column);
|
|
630
|
+
else{
|
|
631
|
+
const rendered=renderRequirementValue(cell.new===null?oldText:newText,column);
|
|
632
|
+
cell.html.unifiedHtml=cell.progress?`${rendered}<small class="progress-note">was ${escapeHtml(oldText||"empty")}</small>`:rendered;
|
|
633
|
+
}
|
|
634
|
+
return cell.html[part];
|
|
635
|
+
}
|
|
636
|
+
function requirementStatus(oldRow,newRow,ignored){
|
|
637
|
+
return rowStatus(oldRow,newRow,data.columns.map(({name})=>name),ignored,comparisonValue);
|
|
638
|
+
}
|
|
639
|
+
function comparisonSource(key=state.compareWith){
|
|
640
|
+
const ignoredColumns=new Set(data.meta.ignoredColumns);
|
|
641
|
+
if(key==="saved")return{kind:"saved",label:"Last save",rows:state.savedRows,inScope:()=>true,ignoredColumns,moves:true};
|
|
642
|
+
if(key==="old")return{kind:"old",label:data.meta.oldFilename??"Old version",rows:data.source.old.rows,inScope:()=>true,ignoredColumns,moves:Boolean(data.options.reviewComparison)};
|
|
643
|
+
const baseline=baselineByKey(key);
|
|
644
|
+
const source=baseline?baselineSource(baseline,state.currentRows,data.meta.idColumn,ignoredColumns):null;
|
|
645
|
+
if(source&&!baseline.capturesStatus)source.progressColumns=new Set(baseline.statusColumns);
|
|
646
|
+
return source;
|
|
647
|
+
}
|
|
648
|
+
function baselineByKey(key){return(data.baselines??[]).find(baseline=>"baseline:"+baseline.name===key);}
|
|
649
|
+
function setCompareWith(next){
|
|
650
|
+
const live=key=>key!==null&&key!=="old",was=live(state.compareWith),now=live(next);
|
|
651
|
+
if(now&&!was){state.previousStatuses=state.statuses;state.statuses=new Set(["added","removed","changed"]);}
|
|
652
|
+
else if(was&&!now)state.statuses=state.previousStatuses;
|
|
653
|
+
state.compareWith=next;
|
|
654
|
+
}
|
|
655
|
+
function movedRowIds(oldRows,newRows){
|
|
656
|
+
const position=new Map([...oldRows.keys()].filter(id=>newRows.has(id)).map((id,i)=>[id,i]));
|
|
657
|
+
const current=[...newRows.keys()].filter(id=>position.has(id)),tails=[],prev=[];
|
|
658
|
+
current.forEach((id,i)=>{
|
|
659
|
+
const value=position.get(id);let lo=0,hi=tails.length;
|
|
660
|
+
while(lo<hi){const mid=(lo+hi)>>1;if(position.get(current[tails[mid]])<value)lo=mid+1;else hi=mid;}
|
|
661
|
+
prev[i]=lo?tails[lo-1]:-1;tails[lo]=i;
|
|
662
|
+
});
|
|
663
|
+
const stay=new Set();
|
|
664
|
+
for(let i=tails.length?tails[tails.length-1]:-1;i>=0;i=prev[i])stay.add(current[i]);
|
|
665
|
+
return new Set(current.filter(id=>!stay.has(id)));
|
|
666
|
+
}
|
|
667
|
+
function diffStatuses(source,{includeMoves=false,includeUnchanged=true}={}){
|
|
668
|
+
const moved=includeMoves?movedRowIds(byId(source.rows),byId(state.currentRows)):new Set();
|
|
669
|
+
const statuses=Object.create(null);
|
|
670
|
+
for(const{id,oldRow,newRow}of comparisonPairs(state.currentRows,source,data.meta.idColumn)){
|
|
671
|
+
const status=moved.has(id)?"changed":requirementStatus(oldRow,newRow,source.ignoredColumns);
|
|
672
|
+
if(status!=="unchanged"||includeUnchanged)statuses[id]=status;
|
|
673
|
+
}
|
|
674
|
+
return statuses;
|
|
675
|
+
}
|
|
676
|
+
let savedRowIndex,rowModels=new Map(),rowModelSource=null,rowModelKey=null;
|
|
677
|
+
function rebuildRows(){
|
|
678
|
+
const key=[dataVersion,state.compareWith,state.savedRows];
|
|
679
|
+
if(rowModelKey?.every((part,i)=>part===key[i]))return;
|
|
680
|
+
rowModelKey=key;
|
|
681
|
+
savedRowIndex=byId(state.savedRows);
|
|
682
|
+
const source=comparisonSource(),moved=source?.moves?movedRowIds(byId(source.rows),byId(state.currentRows)):new Set();
|
|
683
|
+
if((source?.rows??null)!==rowModelSource){rowModels=new Map();rowModelSource=source?.rows??null;}
|
|
684
|
+
data.rows=comparisonPairs(state.currentRows,source,data.meta.idColumn).map(({id,oldRow,newRow},index)=>{
|
|
685
|
+
const previous=rowModels.get(id),isMoved=moved.has(id);
|
|
686
|
+
if(previous&&previous.moved===isMoved&&data.columns.every(({name})=>
|
|
687
|
+
previous.cells[name].old===cellValue(oldRow,name)&&previous.cells[name].new===cellValue(newRow,name))){
|
|
688
|
+
previous.sourceOrder=index;
|
|
689
|
+
return previous;
|
|
690
|
+
}
|
|
691
|
+
return rowModel(id,oldRow,newRow,index,source,isMoved);
|
|
692
|
+
});
|
|
693
|
+
rowModels=new Map(data.rows.map(row=>[row.id,row]));
|
|
694
|
+
}
|
|
695
|
+
function cellValue(row,name){return row&&Object.hasOwn(row,name)?String(row[name]??""):null;}
|
|
696
|
+
function rowModel(id,oldRow,newRow,sourceOrder,source,moved){
|
|
697
|
+
const status=!source?"unchanged":moved?"changed":requirementStatus(oldRow,newRow,source.ignoredColumns);
|
|
698
|
+
const cells=Object.create(null);
|
|
699
|
+
for(const column of data.columns)cells[column.name]=runtimeCell(column,cellValue(oldRow,column.name),cellValue(newRow,column.name),source);
|
|
700
|
+
return{id,status,moved,sourceOrder,cells};
|
|
701
|
+
}
|
|
702
|
+
// After an edit that changed values in place, rebuilds only the changed rows' models and redraws them where shown.
|
|
703
|
+
// Anything another row, a filter, the sort, a comparison or the trace index could read renders in full instead.
|
|
704
|
+
function renderChanges(changes){
|
|
705
|
+
const since=dataVersion-1,modelsCurrent=rowModelKey?.[0]===since&&rowModelKey[1]===state.compareWith&&rowModelKey[2]===state.savedRows;
|
|
706
|
+
if(!changes||!modelsCurrent||!confinedToRows(changes,{comparing:diffActive(),qualityOnly:quality.only,ranged:!!rangeSelection,
|
|
707
|
+
idColumn:data.meta.idColumn,sortColumn:state.sort?.column??null,filtered:filterActive,traceColumns:trace?trace.indexColumns(since):new Set()}))return render();
|
|
708
|
+
rowModelKey=[dataVersion,state.compareWith,state.savedRows];
|
|
709
|
+
const positions=[];
|
|
710
|
+
for(const {index,id} of changes){
|
|
711
|
+
const previous=rowModels.get(id),model=rowModel(id,null,state.currentRows[index],previous.sourceOrder,null,false);
|
|
712
|
+
data.rows[previous.sourceOrder]=model;
|
|
713
|
+
rowModels.set(id,model);
|
|
714
|
+
const position=grid.display.indexOf(previous);
|
|
715
|
+
if(position<0)continue;
|
|
716
|
+
grid.display[position]=model;
|
|
717
|
+
positions.push(position);
|
|
718
|
+
}
|
|
719
|
+
trace?.keepIndex(since);
|
|
720
|
+
trace?.refresh();
|
|
721
|
+
scanQuality();
|
|
722
|
+
redrawRows(positions);
|
|
723
|
+
setRovingFocus();
|
|
724
|
+
trace?.syncSelection(selectedRequirementId(),true);
|
|
725
|
+
trace?.paintStrip();
|
|
726
|
+
renderQualityPanel();
|
|
727
|
+
positionCellEditor();
|
|
728
|
+
syncModeUi();
|
|
729
|
+
renderPackage?.();
|
|
730
|
+
}
|
|
731
|
+
function canRevertCell(column,cell){
|
|
732
|
+
return developMode()&&diffActive()&&column!==data.meta.idColumn
|
|
733
|
+
&&cell?.changed&&cell.old!==null&&cell.new!==null;
|
|
734
|
+
}
|
|
735
|
+
function revertSelectedCell(){
|
|
736
|
+
if(state.editingCell)return;
|
|
737
|
+
const row=grid.display[state.focus.row],id=row?.id,column=visibleColumns()[state.focus.column]?.name;
|
|
738
|
+
const cell=row?.cells[column];
|
|
739
|
+
if(!canRevertCell(column,cell))return;
|
|
740
|
+
const current=findCurrentRow(id);
|
|
741
|
+
if(!current)return;
|
|
742
|
+
remember();
|
|
743
|
+
current[column]=cell.old;
|
|
744
|
+
updateDirty();
|
|
745
|
+
render();
|
|
746
|
+
if(!focusRequirement(id,column))restoreSelectedCell();
|
|
747
|
+
}
|
|
748
|
+
function insertAtBaselinePosition(items,baseline,index,item,identify){
|
|
749
|
+
const positions=new Map(items.map((value,i)=>[identify(value),i]));
|
|
750
|
+
const next=baseline.slice(index+1).find(value=>positions.has(identify(value)));
|
|
751
|
+
items.splice(next?positions.get(identify(next)):items.length,0,item);
|
|
752
|
+
}
|
|
753
|
+
function restoreDeletedRequirement(){
|
|
754
|
+
if(!developMode()||!diffActive()||state.editingCell)return;
|
|
755
|
+
const id=selectedRequirementId();
|
|
756
|
+
const source=comparisonSource(),baseline=source.rows;
|
|
757
|
+
const index=baseline.findIndex(row=>rowId(row)===id);
|
|
758
|
+
if(index<0||findCurrentRow(id))return;
|
|
759
|
+
const column=visibleColumns()[state.focus.column]?.name;
|
|
760
|
+
const restored=Object.fromEntries(data.source.new.headers.map(name=>[name,baseline[index][name]??""]));
|
|
761
|
+
remember();
|
|
762
|
+
insertAtBaselinePosition(state.currentRows,baseline,index,restored,rowId);
|
|
763
|
+
if(source.kind==="saved"){
|
|
764
|
+
const existingIds=new Set(state.comments.map(comment=>comment.id));
|
|
765
|
+
state.savedComments.forEach((comment,i)=>{
|
|
766
|
+
if(comment.requirementId===id&&!existingIds.has(comment.id)){
|
|
767
|
+
insertAtBaselinePosition(state.comments,state.savedComments,i,cloneValue(comment),value=>value.id);
|
|
768
|
+
}
|
|
769
|
+
});
|
|
770
|
+
}
|
|
771
|
+
updateDirty();
|
|
772
|
+
render();
|
|
773
|
+
if(!focusRequirement(id,column))restoreSelectedCell();
|
|
774
|
+
}
|
|
775
|
+
function renderCellEditor(id,column,value,expanded,compact){
|
|
776
|
+
const heading=expanded?`<div class="cell-editor-label">${escapeHtml(column.label)} · ${escapeHtml(id||"New requirement")}</div>`:"";
|
|
777
|
+
return `<form class="cell-editor${expanded?" cell-editor-expanded":""}${compact?" cell-editor-compact":""}" data-cell-editor data-row-id="${escapeHtml(id)}" data-column="${escapeHtml(column.name)}">${heading}<textarea${compact?' rows="1"':""} aria-label="Edit ${escapeHtml(column.label)}">
|
|
778
|
+
${escapeHtml(value)}</textarea><div class="cell-suggestions" role="group" aria-label="Suggested values" hidden></div><div class="cell-editor-actions"><button class="apply-edit" type="submit" aria-label="Apply" title="Apply">✓</button><button class="cancel-edit" type="button" data-cancel-cell-edit aria-label="Cancel" title="Cancel">✕</button></div></form>`;
|
|
779
|
+
}
|
|
780
|
+
function renderBooleanCell(row,column){
|
|
781
|
+
const on=booleanOn(valueFor(row,column.name));
|
|
782
|
+
return `<span class="bool-cell" role="checkbox" aria-checked="${on}"${developMode()?"":' aria-readonly="true"'} aria-label="${escapeHtml(column.label)} for ${escapeHtml(row.id)}" data-bool-toggle><span class="bool-box" aria-hidden="true"></span></span>`;
|
|
783
|
+
}
|
|
784
|
+
function toggleBooleanCell(cell){
|
|
785
|
+
const rid=cell.closest("tr")?.dataset.rowId,column=cell.dataset.column,row=findCurrentRow(rid);
|
|
786
|
+
if(!developMode()||state.editingCell||!row||!data.source.new.headers.includes(column)||!booleanApplies(column,trace?.recordType(rid)))return false;
|
|
787
|
+
remember();
|
|
788
|
+
row[column]=booleanToggle(row[column]);
|
|
789
|
+
updateDirty();
|
|
790
|
+
render();
|
|
791
|
+
focusRequirement(rid,column);
|
|
792
|
+
return true;
|
|
793
|
+
}
|
|
794
|
+
function renderCell(row,column){
|
|
795
|
+
const cell=row.cells[column.name],count=grid.comments.get(commentKey(row.id,column.name))??0;
|
|
796
|
+
const edit=state.editingCell;
|
|
797
|
+
const editor=edit?.rid===row.id&&edit.column===column.name
|
|
798
|
+
?renderCellEditor(row.id,column,edit.draft??valueFor(row,column.name),edit.expanded,edit.source.defined):"";
|
|
799
|
+
if(editor&&!edit.expanded)return editor;
|
|
800
|
+
let content;if(row.id!==""&&diffActive()&&state.view==="side-by-side"&&(cell.changed||cell.old===null||cell.new===null)){content=`<div class="split"><div class="pane"><span class="pane-label">Old</span>${cell.old===null?'<div class="missing">Not present</div>':cellHtml(cell,column,"oldHtml")}</div><div class="pane"><span class="pane-label">New</span>${cell.new===null?'<div class="missing">Not present</div>':cellHtml(cell,column,"newHtml")}</div></div>`;}else if(row.id===""){
|
|
801
|
+
if(column.name===data.meta.idColumn)content='<button type="button" class="entry-add" tabindex="-1" data-add-entry aria-label="Add requirement…" title="Add requirement…">+</button>';
|
|
802
|
+
else if(column.name.toLowerCase()==="requirement"&&data.source.new.headers.includes(column.name)){
|
|
803
|
+
content='<span class="entry-hint">Type to add a requirement…</span>';
|
|
804
|
+
}else content="";
|
|
805
|
+
}else content=(booleanApplies(column.name,trace?.recordType(row.id))&&renderBooleanCell(row,column))||(!cell.changed&&trace?.cellDisplay(row.id,column.name))||cellHtml(cell,column,"unifiedHtml");const allowed=row.id!==""&&data.options.commentsEnabled&&column.name!==data.meta.idColumn,button=allowed?`<button class="comment-button ${count?'has-comments':''}" data-comment-row="${escapeHtml(row.id)}" data-comment-column="${escapeHtml(column.name)}" aria-label="${count?`${count} comments`:'Add comment'} for ${escapeHtml(row.id)}, ${escapeHtml(column.label)}">${count||'+'}</button>`:"",saved=savedRowIndex.get(row.id),edited=developMode()&&cell.new!==null&&String(saved?.[column.name]??"")!==cell.new;
|
|
806
|
+
return `<div class="cell-wrap markdown ${edited?'edited-cell':''}">${content}</div>${button}${editor}`;}
|
|
807
|
+
function firstDataColumn(){return diffActive()?2:1;}function statusHead(){return diffActive()?'<th scope="col" role="columnheader" aria-colindex="1" class="heading-cell">Status</th>':"";}function statusFilterHead(){return diffActive()?'<th role="gridcell" aria-colindex="1"><span class="sr-only">Status filters</span></th>':"";}function statusCell(row){return diffActive()?(row.id===""?'<td role="gridcell" aria-colindex="1" class="status-cell"></td>':`<td role="gridcell" aria-colindex="1" class="status-cell"><span class="badge ${row.status}">${row.status}</span>${row.moved?'<small class="order-change">Order changed</small>':""}</td>`):"";}
|
|
808
|
+
const resizedColumns=new Set();
|
|
809
|
+
function setColumnWidth(column,width){
|
|
810
|
+
const widths=trace?.columnLayout()?.overrides??state.widths;
|
|
811
|
+
widths.set(column,width);
|
|
812
|
+
resizedColumns.add(column);
|
|
813
|
+
}
|
|
814
|
+
function freezeColumnWidths(){
|
|
815
|
+
if(trace?.columnLayout())return;
|
|
816
|
+
for(const cell of headRow.querySelectorAll("th[data-header-column]"))state.widths.set(cell.dataset.headerColumn,cell.getBoundingClientRect().width);
|
|
817
|
+
}
|
|
818
|
+
function resetColumnWidths(){
|
|
819
|
+
const layout=trace?.columnLayout();
|
|
820
|
+
resizedColumns.clear();
|
|
821
|
+
if(layout)layout.overrides.clear();
|
|
822
|
+
else state.widths=new Map(data.columns.map(c=>[c.name,configuredPixels(c)]));
|
|
823
|
+
}
|
|
824
|
+
function renderLayout(){
|
|
825
|
+
const columns=visibleColumns(),status=diffActive()?118:0,layout=trace?.columnLayout();
|
|
826
|
+
const widths=columns.map(column=>layout
|
|
827
|
+
?layout.overrides.get(column.name)??configuredPixels(column,layout.defaults.get(column.name))
|
|
828
|
+
:state.widths.get(column.name));
|
|
829
|
+
const natural=status+widths.reduce((sum,width)=>sum+width,0);
|
|
830
|
+
const available=$(".table-wrap").clientWidth;
|
|
831
|
+
let target=Math.max(available,natural);
|
|
832
|
+
if(layout){
|
|
833
|
+
const flexible=columns.flatMap(({name,width},i)=>
|
|
834
|
+
layout.flexible.has(name)&&!width&&!layout.overrides.has(name)?[i]:[]);
|
|
835
|
+
if(flexible.length){
|
|
836
|
+
for(const index of flexible)widths[index]+=(target-natural)/flexible.length;
|
|
837
|
+
}else target=natural;
|
|
838
|
+
}else if(target>natural){
|
|
839
|
+
const free=widths.map((width,i)=>resizedColumns.has(columns[i].name)?-1:width);
|
|
840
|
+
const widest=free.indexOf(Math.max(...free));
|
|
841
|
+
if(free[widest]>=0)widths[widest]+=target-natural;
|
|
842
|
+
else target=natural;
|
|
843
|
+
}
|
|
844
|
+
$("#column-widths").innerHTML=(status?'<col style="width:118px">':"")+columns.map((column,i)=>
|
|
845
|
+
`<col data-col-width="${escapeHtml(column.name)}" style="width:${layout?widths[i]:Math.round(widths[i])}px">`).join("");
|
|
846
|
+
table.style.width=`${target}px`;
|
|
847
|
+
table.style.minWidth=layout?"0":"";
|
|
848
|
+
const idWidth=widths[columns.findIndex(column=>column.name===data.meta.idColumn)];
|
|
849
|
+
table.classList.toggle("compact-row-ids",idWidth<=110);
|
|
850
|
+
useLayoutHeights([state.view,status,trace?.viewKey()??"",...columns.map((column,i)=>`${column.name}:${Math.round(widths[i])}`)].join("\u0000"));
|
|
851
|
+
positionCellEditor();
|
|
852
|
+
}
|
|
853
|
+
function renderBody(){trace?.refresh();scanQuality();const activeFilters=renderActiveFilters();if(!cellDrag)rangeSelection=null;const rows=sortedRows(),cols=visibleColumns();grid.filteredEmpty=filteredToEmpty(activeFilters,rows.length,data.rows.length);grid.canDrag=canDragRows();grid.display=developMode()&&(!trace||trace.entry())?[...rows,{id:"",status:"unchanged",cells:Object.fromEntries(data.columns.map(c=>[c.name,{old:null,new:""}]))}]:rows;indexComments();drawRows();resultCount.textContent=trace?.gridSummary(rows.length)??`${cols.length} of ${data.columns.length} columns · ${rows.length} of ${data.rows.length} requirements`;$("#comments-only-rows").setAttribute("aria-pressed",String(state.commentsOnly));setRovingFocus();trace?.syncSelection(selectedRequirementId(),true);trace?.paintStrip();renderQualityPanel();positionCellEditor();}
|
|
854
|
+
const tableWrap=$(".table-wrap");
|
|
855
|
+
tableWrap.tabIndex=-1;
|
|
856
|
+
function windowed(){return !grid.printing&&grid.display.length>WINDOW_THRESHOLD;}
|
|
857
|
+
function tableScroller(){return tableWrap.scrollHeight>tableWrap.clientHeight+1?tableWrap:document.scrollingElement;}
|
|
858
|
+
function viewportBand(){
|
|
859
|
+
const body=tableBody.getBoundingClientRect(),wrap=tableWrap.getBoundingClientRect();
|
|
860
|
+
const top=Math.max(wrap.top,0),bottom=Math.min(wrap.bottom,innerHeight);
|
|
861
|
+
return {top:top-body.top,height:Math.max(0,bottom-top)};
|
|
862
|
+
}
|
|
863
|
+
function cellContext(range){
|
|
864
|
+
return {canDrag:grid.canDrag,focus:state.focus,bounds:range,wholeRows:!!range?.wholeRows,firstColumn:firstDataColumn()};
|
|
865
|
+
}
|
|
866
|
+
function rowsHtml(from,to,cols,context){
|
|
867
|
+
let html="";
|
|
868
|
+
for(let index=from;index<to;index++){
|
|
869
|
+
const row=grid.display[index];
|
|
870
|
+
const drag=rowDrag?.shown&&rowDrag.ids.includes(row.id)?" row-drag-source":"",drop=rowDrag?.target===index?" drop-before":"";
|
|
871
|
+
html+=`<tr class="${row.id===""?"entry-row":`row-${row.status}`}${drag}${drop}" data-row-id="${escapeHtml(row.id)}" data-row-index="${index}" aria-rowindex="${ariaRowIndex(index,+grid.filteredEmpty)}">${statusCell(row)}${cols.map((c,ci)=>dataCell(row,c,index,ci,context)).join("")}</tr>`;
|
|
872
|
+
}
|
|
873
|
+
return html;
|
|
874
|
+
}
|
|
875
|
+
function filteredEmptyRow(){
|
|
876
|
+
if(!grid.filteredEmpty)return "";
|
|
877
|
+
const noun=trace&&trace.recordNoun?trace.recordNoun():"requirements";
|
|
878
|
+
return `<tr class="filtered-empty" aria-rowindex="${GRID_HEAD_ROWS+1}"><td role="gridcell" aria-colindex="1" colspan="${grid.columns}"><strong>No ${noun} match the current filters.</strong> <button type="button" data-clear-filters>Clear filters</button></td></tr>`;
|
|
879
|
+
}
|
|
880
|
+
function spacerRow(height){return `<tr class="window-spacer" role="presentation" aria-hidden="true"><td colspan="${grid.columns}" style="height:${height}px"></td></tr>`;}
|
|
881
|
+
function renderedRows(){return tableBody.querySelectorAll("tr[data-row-index]");}
|
|
882
|
+
function decorateRows(rows){paintQualityMarkers(rows);trace?.paintMarkers(rows);trace?.linkGlossary(rows);}
|
|
883
|
+
function useLayoutHeights(key){
|
|
884
|
+
if(key===grid.layoutKey)return;
|
|
885
|
+
grid.layoutKey=key;
|
|
886
|
+
grid.heights=grid.layouts.get(key)??new Map();
|
|
887
|
+
grid.layouts.delete(key);
|
|
888
|
+
grid.layouts.set(key,grid.heights);
|
|
889
|
+
while(grid.layouts.size>8)grid.layouts.delete(grid.layouts.keys().next().value);
|
|
890
|
+
grid.stale=true;
|
|
891
|
+
scheduleWindow();
|
|
892
|
+
}
|
|
893
|
+
function measureRows(){
|
|
894
|
+
let changed=false;
|
|
895
|
+
for(const row of renderedRows()){
|
|
896
|
+
const id=grid.display[+row.dataset.rowIndex].id,height=row.getBoundingClientRect().height;
|
|
897
|
+
if(grid.heights.get(id)!==height){grid.heights.set(id,height);changed=true;}
|
|
898
|
+
}
|
|
899
|
+
if(changed)grid.offsets=rowOffsets(grid.display.map(row=>row.id),grid.heights);
|
|
900
|
+
tableBody.firstElementChild.firstElementChild.style.height=`${grid.offsets[grid.start]}px`;
|
|
901
|
+
tableBody.lastElementChild.firstElementChild.style.height=`${grid.offsets.at(-1)-grid.offsets[grid.end]}px`;
|
|
902
|
+
}
|
|
903
|
+
function anchorRow(band){return rowElement(windowRange(grid.offsets,band.top,0,0,-1).start);}
|
|
904
|
+
function keepInPlace(anchor,before){
|
|
905
|
+
if(!anchor?.isConnected)return;
|
|
906
|
+
const shift=anchor.getBoundingClientRect().top-before;
|
|
907
|
+
if(Math.abs(shift)>.5)tableScroller().scrollTop+=shift;
|
|
908
|
+
}
|
|
909
|
+
function parkFocus(active){
|
|
910
|
+
if(active&&active!==document.body&&!active.isConnected)tableWrap.focus({preventScroll:true});
|
|
911
|
+
}
|
|
912
|
+
function redrawRows(positions){
|
|
913
|
+
const cols=visibleColumns(),context=cellContext(currentRange()),active=document.activeElement,drawn=[];
|
|
914
|
+
for(const position of positions){
|
|
915
|
+
const old=rowElement(position);
|
|
916
|
+
if(!old)continue;
|
|
917
|
+
old.insertAdjacentHTML("afterend",rowsHtml(position,position+1,cols,context));
|
|
918
|
+
drawn.push(old.nextElementSibling);
|
|
919
|
+
old.remove();
|
|
920
|
+
}
|
|
921
|
+
decorateRows(drawn);
|
|
922
|
+
if(windowed()&&drawn.length){
|
|
923
|
+
const anchor=anchorRow(viewportBand()),before=anchor?.getBoundingClientRect().top;
|
|
924
|
+
measureRows();
|
|
925
|
+
keepInPlace(anchor,before);
|
|
926
|
+
}
|
|
927
|
+
parkFocus(active);
|
|
928
|
+
}
|
|
929
|
+
function drawRows(){
|
|
930
|
+
paintedRange=currentRange();
|
|
931
|
+
const cols=visibleColumns(),count=grid.display.length,context=cellContext(paintedRange),active=document.activeElement;
|
|
932
|
+
grid.columns=cols.length+(diffActive()?1:0);
|
|
933
|
+
table.setAttribute("aria-rowcount",ariaRowIndex(count-1,+grid.filteredEmpty));
|
|
934
|
+
table.setAttribute("aria-colcount",grid.columns);
|
|
935
|
+
if(!windowed()){
|
|
936
|
+
grid.start=0;
|
|
937
|
+
grid.end=count;
|
|
938
|
+
tableBody.innerHTML=filteredEmptyRow()+rowsHtml(0,count,cols,context);
|
|
939
|
+
decorateRows(tableBody.rows);
|
|
940
|
+
return;
|
|
941
|
+
}
|
|
942
|
+
grid.offsets=rowOffsets(grid.display.map(row=>row.id),grid.heights);
|
|
943
|
+
const band=viewportBand(),range=windowRange(grid.offsets,band.top,band.height);
|
|
944
|
+
grid.start=range.start;
|
|
945
|
+
grid.end=range.end;
|
|
946
|
+
tableBody.innerHTML=spacerRow(range.top)+rowsHtml(range.start,range.end,cols,context)+spacerRow(range.bottom);
|
|
947
|
+
decorateRows(renderedRows());
|
|
948
|
+
const anchor=anchorRow(band),before=anchor?.getBoundingClientRect().top;
|
|
949
|
+
measureRows();
|
|
950
|
+
keepInPlace(anchor,before);
|
|
951
|
+
parkFocus(active);
|
|
952
|
+
}
|
|
953
|
+
function scheduleWindow(){if(!grid.frame)grid.frame=requestAnimationFrame(updateWindow);}
|
|
954
|
+
function updateWindow(){
|
|
955
|
+
grid.frame=0;
|
|
956
|
+
if(!windowed()||!tableBody.firstElementChild)return;
|
|
957
|
+
if(grid.stale){
|
|
958
|
+
grid.stale=false;
|
|
959
|
+
const anchor=anchorRow(viewportBand()),before=anchor?.getBoundingClientRect().top;
|
|
960
|
+
measureRows();
|
|
961
|
+
keepInPlace(anchor,before);
|
|
962
|
+
}
|
|
963
|
+
const band=viewportBand(),near=windowRange(grid.offsets,band.top,band.height,5,-1);
|
|
964
|
+
if(near.start>=grid.start&&near.end<=grid.end)return;
|
|
965
|
+
const {start,end}=windowRange(grid.offsets,band.top,band.height,WINDOW_OVERSCAN,-1);
|
|
966
|
+
const keptStart=Math.max(start,grid.start),keptEnd=Math.min(end,grid.end);
|
|
967
|
+
if(keptStart>=keptEnd){drawRows();return;}
|
|
968
|
+
const active=document.activeElement,cols=visibleColumns(),context=cellContext(paintedRange);
|
|
969
|
+
const anchor=rowElement(keptStart),before=anchor.getBoundingClientRect().top;
|
|
970
|
+
for(const row of renderedRows()){
|
|
971
|
+
const index=+row.dataset.rowIndex;
|
|
972
|
+
if(index<start||index>=end)row.remove();
|
|
973
|
+
}
|
|
974
|
+
anchor.insertAdjacentHTML("beforebegin",rowsHtml(start,keptStart,cols,context));
|
|
975
|
+
rowElement(keptEnd-1).insertAdjacentHTML("afterend",rowsHtml(keptEnd,end,cols,context));
|
|
976
|
+
grid.start=start;
|
|
977
|
+
grid.end=end;
|
|
978
|
+
decorateRows([...renderedRows()].filter(row=>+row.dataset.rowIndex<keptStart||+row.dataset.rowIndex>=keptEnd));
|
|
979
|
+
measureRows();
|
|
980
|
+
keepInPlace(anchor,before);
|
|
981
|
+
parkFocus(active);
|
|
982
|
+
}
|
|
983
|
+
function revealRow(index){
|
|
984
|
+
if(!windowed()||(index>=grid.start&&index<grid.end))return;
|
|
985
|
+
const band=viewportBand();
|
|
986
|
+
tableScroller().scrollTop+=grid.offsets[index]-band.top-band.height/3;
|
|
987
|
+
updateWindow();
|
|
988
|
+
}
|
|
989
|
+
tableWrap.addEventListener("scroll",scheduleWindow,{passive:true});
|
|
990
|
+
window.addEventListener("scroll",scheduleWindow,{passive:true});
|
|
991
|
+
window.addEventListener("resize",scheduleWindow);
|
|
992
|
+
window.addEventListener("beforeprint",()=>{
|
|
993
|
+
if(tableWrap.hidden||!windowed())return;
|
|
994
|
+
grid.printing={focused:tableBody.contains(document.activeElement)};
|
|
995
|
+
drawRows();
|
|
996
|
+
});
|
|
997
|
+
window.addEventListener("afterprint",()=>{
|
|
998
|
+
if(!grid.printing)return;
|
|
999
|
+
const {focused}=grid.printing;
|
|
1000
|
+
grid.printing=false;
|
|
1001
|
+
drawRows();
|
|
1002
|
+
if(focused)cellElement(state.focus.row,state.focus.column)?.focus({preventScroll:true});
|
|
1003
|
+
});
|
|
1004
|
+
function renderCompareMenu(){
|
|
1005
|
+
const baselines=data.baselines??[],hasOld=data.meta.mode==="diff"&&Boolean(data.source.old),box=$("#compare-baselines"),old=$("#compare-old");
|
|
1006
|
+
$("#compare-menu").hidden=!developMode()&&!hasOld&&!baselines.length;
|
|
1007
|
+
old.hidden=!hasOld;
|
|
1008
|
+
if(hasOld)old.textContent=data.meta.oldFilename??"Old version";
|
|
1009
|
+
if(!box.childElementCount)for(const baseline of baselines){
|
|
1010
|
+
const button=document.createElement("button");
|
|
1011
|
+
button.type="button";
|
|
1012
|
+
button.dataset.compare="baseline:"+baseline.name;
|
|
1013
|
+
button.textContent=`${baseline.name} · ${baseline.created.slice(0,10)}`;
|
|
1014
|
+
box.append(button);
|
|
1015
|
+
}
|
|
1016
|
+
for(const button of $("#compare-menu").querySelectorAll("[data-compare]"))button.setAttribute("aria-pressed",String(button.dataset.compare===(state.compareWith??"none")));
|
|
1017
|
+
const active=baselineByKey(state.compareWith),line=$("#comparison-line");
|
|
1018
|
+
line.hidden=!active;
|
|
1019
|
+
line.replaceChildren();
|
|
1020
|
+
if(!active)return;
|
|
1021
|
+
line.append(`Comparing with ${active.name} (${active.produces}, ${active.created.slice(0,10)}) · ${active.hash.slice(0,"sha256:".length+12)}`);
|
|
1022
|
+
if(!active.hashOk){
|
|
1023
|
+
const warning=document.createElement("span");
|
|
1024
|
+
warning.className="warning";
|
|
1025
|
+
warning.textContent=" · content does not match its recorded hash";
|
|
1026
|
+
line.append(warning);
|
|
1027
|
+
}
|
|
1028
|
+
}
|
|
1029
|
+
function syncModeUi(){
|
|
1030
|
+
const comparison=$("#review-comparison");
|
|
1031
|
+
comparison.hidden=!data.options.reviewComparison;
|
|
1032
|
+
comparison.textContent=state.compareWith===null?"Show changes since last save":"Show current requirements";
|
|
1033
|
+
if(trace){
|
|
1034
|
+
for(const id of ["add-end","add-above","add-below"])$("#"+id).disabled=!trace.entry();
|
|
1035
|
+
for(const id of ["move-up","move-down"])$("#"+id).disabled=trace.scoped();
|
|
1036
|
+
$("#rename-requirement").disabled=trace.pageView();
|
|
1037
|
+
}
|
|
1038
|
+
document.querySelectorAll(".develop-only").forEach(el=>el.hidden=!developMode());document.querySelectorAll(".diff-only").forEach(el=>el.hidden=!diffActive());if(!data.options.commentsEnabled)document.querySelectorAll(".comments-only").forEach(el=>el.hidden=true);renderCompareMenu();$("#undo-edit").disabled=!state.undo.length;$("#redo-edit").disabled=!state.redo.length;}function render(){rebuildRows();renderLayout();renderHead();renderBody();$("#view-toggle").textContent=state.view==="unified"?"Side-by-side view":"Unified view";renderColumnChooser();renderStatusControls();syncModeUi();renderPackage?.();}function renderBodyOnly(){renderBody();renderColumnChooser();}
|
|
1039
|
+
// Rows and comments are flat records of primitive values, so a per-record spread is a full copy that shares the strings.
|
|
1040
|
+
function cloneRecords(records){return records.map(record=>({...record}));}
|
|
1041
|
+
function sameRecord(x,y){
|
|
1042
|
+
if(x===y)return true;
|
|
1043
|
+
let count=0;
|
|
1044
|
+
for(const key in x){const value=x[key];if(value!==y[key]||(value===undefined&&!Object.hasOwn(y,key)))return false;count++;}
|
|
1045
|
+
for(const key in y)count--;
|
|
1046
|
+
return !count;
|
|
1047
|
+
}
|
|
1048
|
+
function sameRecords(a,b){
|
|
1049
|
+
if(a.length!==b.length)return false;
|
|
1050
|
+
for(let i=0;i<a.length;i++)if(!sameRecord(a[i],b[i]))return false;
|
|
1051
|
+
return true;
|
|
1052
|
+
}
|
|
1053
|
+
// Each record whose values differ, with its position and the columns that differ, or null when the lists do not
|
|
1054
|
+
// hold the same ids in the same order.
|
|
1055
|
+
function changedRecords(before,after,idOf){
|
|
1056
|
+
if(before.length!==after.length)return null;
|
|
1057
|
+
const changes=[];
|
|
1058
|
+
for(let index=0;index<before.length;index++){
|
|
1059
|
+
const x=before[index],y=after[index];
|
|
1060
|
+
if(sameRecord(x,y))continue;
|
|
1061
|
+
const id=idOf(y);
|
|
1062
|
+
if(idOf(x)!==id)return null;
|
|
1063
|
+
const columns=new Set();
|
|
1064
|
+
for(const key in x)if(x[key]!==y[key]||!Object.hasOwn(y,key))columns.add(key);
|
|
1065
|
+
for(const key in y)if(!Object.hasOwn(x,key))columns.add(key);
|
|
1066
|
+
changes.push({index,id,columns});
|
|
1067
|
+
}
|
|
1068
|
+
return changes;
|
|
1069
|
+
}
|
|
1070
|
+
// Whether redrawing the changed rows alone shows the same table as a full render: no changed column may decide row
|
|
1071
|
+
// order, row membership, a comparison status or the trace index (traceColumns null means it reads every column).
|
|
1072
|
+
function confinedToRows(changes,{comparing,qualityOnly,ranged,idColumn,sortColumn,filtered,traceColumns}){
|
|
1073
|
+
if(comparing||qualityOnly||ranged||!traceColumns)return false;
|
|
1074
|
+
for(const {columns} of changes){
|
|
1075
|
+
for(const column of columns){
|
|
1076
|
+
if(column===idColumn||column===sortColumn||filtered(column)||traceColumns.has(column))return false;
|
|
1077
|
+
}
|
|
1078
|
+
}
|
|
1079
|
+
return true;
|
|
1080
|
+
}
|
|
1081
|
+
// Every edit to rows, comments, quality review or decisions reports here, so caches of derived data key off this counter.
|
|
1082
|
+
let dataVersion=0;
|
|
1083
|
+
function updateDirty(){
|
|
1084
|
+
dataVersion++;
|
|
1085
|
+
state.requirementsDirty=!sameRecords(state.currentRows,state.savedRows);
|
|
1086
|
+
state.commentsDirty=!sameRecords(state.comments,state.savedComments);
|
|
1087
|
+
state.qualityDirty=JSON.stringify(state.qualityReview)!==JSON.stringify(state.savedQualityReview);
|
|
1088
|
+
state.decisionsDirty=JSON.stringify(state.decisions)!==JSON.stringify(state.savedDecisions);
|
|
1089
|
+
state.dirty=state.requirementsDirty||state.commentsDirty||state.qualityDirty||state.decisionsDirty;
|
|
1090
|
+
const changed=[];
|
|
1091
|
+
if(state.requirementsDirty)changed.push("requirements");
|
|
1092
|
+
if(state.commentsDirty)changed.push("comments");
|
|
1093
|
+
if(state.decisionsDirty)changed.push("decisions");
|
|
1094
|
+
if(state.qualityDirty)changed.push("quality settings and dismissals (save a report copy)");
|
|
1095
|
+
const label=changed.length?"Unsaved "+changed.join(" and "):"";
|
|
1096
|
+
$("#dirty-details").textContent=label;
|
|
1097
|
+
const announcement=$("#dirty-announcement"),indicator=$("#dirty-indicator");
|
|
1098
|
+
if(announcement.textContent!==label)announcement.textContent=label;
|
|
1099
|
+
indicator.hidden=!state.dirty;
|
|
1100
|
+
if(!state.dirty)indicator.open=false;
|
|
1101
|
+
scheduleAutosave();
|
|
1102
|
+
draftChanged();
|
|
1103
|
+
}
|
|
1104
|
+
window.addEventListener("beforeunload",event=>{if(!state.dirty)return;event.preventDefault();event.returnValue="";});
|
|
1105
|
+
function setDirty(value){if(!value){state.savedComments=cloneValue(state.comments);state.savedDecisions=cloneValue(state.decisions);}updateDirty();}
|
|
1106
|
+
function historySnapshot(){return {rows:cloneRecords(state.currentRows),comments:cloneRecords(state.comments)};}
|
|
1107
|
+
function remember(){state.undo.push(historySnapshot());if(state.undo.length>100)state.undo.shift();state.redo=[];}
|
|
1108
|
+
// Takes ownership of the snapshot's arrays; callers pass records nothing else holds.
|
|
1109
|
+
function restoreHistory(snapshot){
|
|
1110
|
+
const changes=!state.editingCell&&sameRecords(state.comments,snapshot.comments)?changedRecords(state.currentRows,snapshot.rows,rowId):null;
|
|
1111
|
+
if(changes){
|
|
1112
|
+
// Restore values into the live records so records keep their identity, which the trace index relies on.
|
|
1113
|
+
for(const {index} of changes){
|
|
1114
|
+
const live=state.currentRows[index],restored=snapshot.rows[index];
|
|
1115
|
+
for(const key in live)if(!Object.hasOwn(restored,key))delete live[key];
|
|
1116
|
+
Object.assign(live,restored);
|
|
1117
|
+
}
|
|
1118
|
+
}else{
|
|
1119
|
+
state.currentRows=snapshot.rows;
|
|
1120
|
+
state.comments=snapshot.comments;
|
|
1121
|
+
}
|
|
1122
|
+
state.editingCell=null;
|
|
1123
|
+
updateDirty();
|
|
1124
|
+
renderChanges(changes);
|
|
1125
|
+
}
|
|
1126
|
+
function undoEdit(){if(!state.undo.length)return;state.redo.push(historySnapshot());restoreHistory(state.undo.pop());}
|
|
1127
|
+
function redoEdit(){if(!state.redo.length)return;state.undo.push(historySnapshot());restoreHistory(state.redo.pop());}
|
|
1128
|
+
function selectedRequirementId(){return grid.display[state.focus.row]?.id||null;}function findCurrentRow(id){return state.currentRows.find(row=>rowId(row)===id);}function validateNewId(value,current=null){const id=String(value??"").trim();if(!id){alert("The ID cannot be empty.");return null;}if(trace&&id.includes(";")){alert("A traceable ID cannot contain a semicolon.");return null;}if(state.currentRows.some(row=>rowId(row)===id&&rowId(row)!==current)){alert(`ID ${id} already exists.`);return null;}return id;}
|
|
1129
|
+
function nextRecordId(preferredPrefix=null){
|
|
1130
|
+
const rows=[...state.currentRows,...state.savedRows,...(data.source.old?.rows??[])];
|
|
1131
|
+
const families=new Map();
|
|
1132
|
+
for(const row of rows){
|
|
1133
|
+
const match=rowId(row).match(/^(.*?)([0-9]+)$/);
|
|
1134
|
+
if(!match)continue;
|
|
1135
|
+
const [,prefix,digits]=match;
|
|
1136
|
+
if(trace&&prefix.includes(";"))continue;
|
|
1137
|
+
const family=families.get(prefix)??{count:0,max:0n,width:0};
|
|
1138
|
+
if(!trace||traceType(row)!=="Term")family.count++;
|
|
1139
|
+
const number=BigInt(digits);
|
|
1140
|
+
if(number>family.max)family.max=number;
|
|
1141
|
+
family.width=Math.max(family.width,digits.length);
|
|
1142
|
+
families.set(prefix,family);
|
|
1143
|
+
}
|
|
1144
|
+
const prefix=preferredPrefix??[...families].filter(([,family])=>family.count)
|
|
1145
|
+
.sort((a,b)=>b[1].count-a[1].count)[0]?.[0]??"REQ-";
|
|
1146
|
+
const family=families.get(prefix)??{max:0n,width:3};
|
|
1147
|
+
return prefix+String(family.max+1n).padStart(family.width,"0");
|
|
1148
|
+
}
|
|
1149
|
+
function newRequirement(id){
|
|
1150
|
+
return Object.fromEntries(data.source.new.headers.map(header=>[header,header===data.meta.idColumn?id:""]));
|
|
1151
|
+
}
|
|
1152
|
+
function focusRequirement(id,column){
|
|
1153
|
+
const row=displayIndex(id),columns=visibleColumns();
|
|
1154
|
+
if(row<0||!columns.length)return null;
|
|
1155
|
+
let index=columns.findIndex(c=>c.name===column);
|
|
1156
|
+
if(index<0)index=Math.max(0,columns.findIndex(c=>c.name!==data.meta.idColumn));
|
|
1157
|
+
focusGridCell(row,index);
|
|
1158
|
+
return cellElement(row,index);
|
|
1159
|
+
}
|
|
1160
|
+
function addRequirement(position){
|
|
1161
|
+
if(state.editingCell||(trace&&!trace.entry()))return;
|
|
1162
|
+
const selected=state.currentRows.findIndex(row=>rowId(row)===selectedRequirementId());
|
|
1163
|
+
if(selected<0&&position!=="end"){alert("Select a current record first.");return;}
|
|
1164
|
+
const proposed=prompt(`New requirement ID (${data.meta.idColumn}):`,nextRecordId());
|
|
1165
|
+
if(proposed===null)return;
|
|
1166
|
+
const id=validateNewId(proposed);
|
|
1167
|
+
if(!id)return;
|
|
1168
|
+
const index=position==="end"?state.currentRows.length:selected+(position==="below"?1:0);
|
|
1169
|
+
remember();
|
|
1170
|
+
const row=newRequirement(id);
|
|
1171
|
+
trace?.allocate(row);
|
|
1172
|
+
state.currentRows.splice(index,0,row);
|
|
1173
|
+
state.sort=null;
|
|
1174
|
+
updateDirty();
|
|
1175
|
+
render();
|
|
1176
|
+
let cell=focusRequirement(id,trace?"Requirement":undefined);
|
|
1177
|
+
if(!cell){
|
|
1178
|
+
state.filters.clear();
|
|
1179
|
+
state.valueFilters.clear();
|
|
1180
|
+
state.commentsOnly=false;
|
|
1181
|
+
state.idFilter=null;
|
|
1182
|
+
state.statuses.add(state.compareWith!==null?"added":"unchanged");
|
|
1183
|
+
render();
|
|
1184
|
+
cell=focusRequirement(id,trace?"Requirement":undefined);
|
|
1185
|
+
}
|
|
1186
|
+
if(cell)startCellEdit(cell,{selection:"all"});
|
|
1187
|
+
}
|
|
1188
|
+
function handleSpreadsheetRowShortcut(event){
|
|
1189
|
+
const command=event.ctrlKey||event.metaKey;
|
|
1190
|
+
const direction=event.key==="ArrowUp"?-1:event.key==="ArrowDown"?1:0;
|
|
1191
|
+
if(event.shiftKey&&direction&&event.altKey&&!command){
|
|
1192
|
+
event.preventDefault();
|
|
1193
|
+
moveRequirement(direction,event.repeat);
|
|
1194
|
+
return true;
|
|
1195
|
+
}
|
|
1196
|
+
let action;
|
|
1197
|
+
if(event.shiftKey&&direction&&command&&!event.altKey){
|
|
1198
|
+
action=direction<0?"add-above":"add-below";
|
|
1199
|
+
}else if(command&&!event.shiftKey&&!event.altKey&&["Backspace","Delete"].includes(event.key)){
|
|
1200
|
+
action="delete-requirement";
|
|
1201
|
+
}else if(!command&&!event.shiftKey&&!event.altKey&&["Backspace","Delete"].includes(event.key)){
|
|
1202
|
+
event.preventDefault();
|
|
1203
|
+
if(!event.repeat)clearSelectedCells();
|
|
1204
|
+
return true;
|
|
1205
|
+
}
|
|
1206
|
+
if(!action)return false;
|
|
1207
|
+
event.preventDefault();
|
|
1208
|
+
if(!event.repeat)$(`#${action}`).click();
|
|
1209
|
+
return true;
|
|
1210
|
+
}
|
|
1211
|
+
function moveRequirement(delta,repeat=false){
|
|
1212
|
+
if(!developMode()||state.editingCell)return;
|
|
1213
|
+
if(trace?.scoped()){
|
|
1214
|
+
if(!repeat)alert("Use All requirements or All fields and clear the system filter before reordering.");
|
|
1215
|
+
return;
|
|
1216
|
+
}
|
|
1217
|
+
const {top,bottom}=selectionBounds();
|
|
1218
|
+
if(top===bottom){
|
|
1219
|
+
const id=selectedRequirementId();
|
|
1220
|
+
const index=(trace?.rowOrderIds()??state.currentRows.map(rowId)).indexOf(id);
|
|
1221
|
+
reorderRequirement(index,index+delta,1,null,true);
|
|
1222
|
+
return;
|
|
1223
|
+
}
|
|
1224
|
+
if(!canDragRows()){
|
|
1225
|
+
if(!repeat)alert("To move several rows, use the normal view in source order with no filters.");
|
|
1226
|
+
return;
|
|
1227
|
+
}
|
|
1228
|
+
const movePosition=position=>({...position,row:position.row+delta});
|
|
1229
|
+
const selection={...rangeSelection,anchor:movePosition(rangeSelection.anchor),
|
|
1230
|
+
extent:movePosition(rangeSelection.extent)};
|
|
1231
|
+
reorderRequirement(top,top+delta,bottom-top+1,selection,true);
|
|
1232
|
+
}
|
|
1233
|
+
function reorderRequirement(index,target,count=1,selection=null,keepGrid=false){
|
|
1234
|
+
const order=trace?.rowOrderIds();
|
|
1235
|
+
const length=order?.length??state.currentRows.length;
|
|
1236
|
+
if(index<0||index+count>length||target<0||target>length-count||index===target)return;
|
|
1237
|
+
const id=order?.[index]??rowId(state.currentRows[index]);
|
|
1238
|
+
const column=visibleColumns()[state.focus.column]?.name;
|
|
1239
|
+
const moveInPlace=keepGrid&&Math.abs(target-index)===1&&canDragRows();
|
|
1240
|
+
const ids=order&&new Set(order);
|
|
1241
|
+
remember();
|
|
1242
|
+
moveRowsInOrder(state.currentRows,rowId,ids,index,target,count);
|
|
1243
|
+
state.sort=null;
|
|
1244
|
+
if(moveInPlace){
|
|
1245
|
+
moveRenderedRows(index,target,count,selection,ids);
|
|
1246
|
+
updateDirty();
|
|
1247
|
+
syncModeUi();
|
|
1248
|
+
return;
|
|
1249
|
+
}
|
|
1250
|
+
updateDirty();
|
|
1251
|
+
render();
|
|
1252
|
+
if(selection){
|
|
1253
|
+
rangeSelection=selection;
|
|
1254
|
+
focusGridCell(selection.extent.row,selection.extent.column,true);
|
|
1255
|
+
}else focusRequirement(id,column);
|
|
1256
|
+
}
|
|
1257
|
+
function moveRowsInOrder(rows,identify,ids,index,target,count){
|
|
1258
|
+
if(!ids){
|
|
1259
|
+
rows.splice(target,0,...rows.splice(index,count));
|
|
1260
|
+
return;
|
|
1261
|
+
}
|
|
1262
|
+
const slots=[];
|
|
1263
|
+
rows.forEach((row,i)=>{if(ids.has(identify(row)))slots.push(i);});
|
|
1264
|
+
const ordered=slots.map(slot=>rows[slot]);
|
|
1265
|
+
ordered.splice(target,0,...ordered.splice(index,count));
|
|
1266
|
+
slots.forEach((slot,i)=>{rows[slot]=ordered[i];});
|
|
1267
|
+
}
|
|
1268
|
+
function moveRenderedRows(index,target,count,selection,ids){
|
|
1269
|
+
const delta=target-index;
|
|
1270
|
+
const first=Math.min(index,target);
|
|
1271
|
+
const last=Math.max(index,target)+count-1;
|
|
1272
|
+
const elements=[];
|
|
1273
|
+
for(let row=first;row<=last;row++)elements.push(rowElement(row));
|
|
1274
|
+
const drawn=elements.every(Boolean);
|
|
1275
|
+
if(drawn){
|
|
1276
|
+
// Move the neighboring row around the block so the focused cell stays attached.
|
|
1277
|
+
if(delta<0)tableBody.insertBefore(elements[0],elements.at(-1).nextSibling);
|
|
1278
|
+
else tableBody.insertBefore(elements.at(-1),elements[0]);
|
|
1279
|
+
elements.splice(target-first,0,...elements.splice(index-first,count));
|
|
1280
|
+
}
|
|
1281
|
+
moveRowsInOrder(data.rows,row=>row.id,ids,index,target,count);
|
|
1282
|
+
moveRowsInOrder(grid.display,row=>row.id,null,index,target,count);
|
|
1283
|
+
if(ids)data.rows.forEach((row,index)=>{row.sourceOrder=index;});
|
|
1284
|
+
for(let row=first;row<=last;row++){
|
|
1285
|
+
if(!ids)data.rows[row].sourceOrder=row;
|
|
1286
|
+
if(!drawn)continue;
|
|
1287
|
+
const element=elements[row-first];
|
|
1288
|
+
element.dataset.rowIndex=row;
|
|
1289
|
+
for(const cell of element.cells)cell.dataset.rowIndex=row;
|
|
1290
|
+
}
|
|
1291
|
+
if(windowed())grid.offsets=rowOffsets(grid.display.map(row=>row.id),grid.heights);
|
|
1292
|
+
if(selection)rangeSelection=selection;
|
|
1293
|
+
else if(rangeSelection){
|
|
1294
|
+
rangeSelection.anchor.row+=delta;
|
|
1295
|
+
rangeSelection.extent.row+=delta;
|
|
1296
|
+
}
|
|
1297
|
+
if(paintedRange){paintedRange.top+=delta;paintedRange.bottom+=delta;}
|
|
1298
|
+
state.focus.row+=delta;
|
|
1299
|
+
if(!drawn){
|
|
1300
|
+
drawRows();
|
|
1301
|
+
focusGridCell(state.focus.row,state.focus.column,true);
|
|
1302
|
+
return;
|
|
1303
|
+
}
|
|
1304
|
+
const cell=cellElement(state.focus.row,state.focus.column);
|
|
1305
|
+
if(document.activeElement!==cell)cell.focus({preventScroll:true});
|
|
1306
|
+
ensureCellVisible(cell);
|
|
1307
|
+
}
|
|
1308
|
+
function renameRequirement(){
|
|
1309
|
+
if(!developMode()||state.editingCell)return;
|
|
1310
|
+
const oldId=selectedRequirementId(),row=oldId&&findCurrentRow(oldId);
|
|
1311
|
+
const kind=trace?"record":"requirement";
|
|
1312
|
+
if(!row){alert(`Select a current ${kind} before renaming it.`);return;}
|
|
1313
|
+
const proposed=prompt(`Rename ${kind} ${oldId}:`,oldId);
|
|
1314
|
+
if(proposed===null)return;
|
|
1315
|
+
const id=validateNewId(proposed,oldId);
|
|
1316
|
+
if(!id||id===oldId)return;
|
|
1317
|
+
const links=trace?.incomingChanges(oldId,id)??[];
|
|
1318
|
+
remember();
|
|
1319
|
+
for(const change of links)change.row[change.field]=change.value;
|
|
1320
|
+
row[data.meta.idColumn]=id;
|
|
1321
|
+
for(const comment of state.comments)if(comment.requirementId===oldId)comment.requirementId=id;
|
|
1322
|
+
if(state.commentContext?.rid===oldId)state.commentContext.rid=id;
|
|
1323
|
+
trace?.rename(oldId,id);
|
|
1324
|
+
const column=visibleColumns()[state.focus.column]?.name;
|
|
1325
|
+
updateDirty();
|
|
1326
|
+
render();
|
|
1327
|
+
focusRequirement(id,column);
|
|
1328
|
+
}
|
|
1329
|
+
function recordKind(type){
|
|
1330
|
+
if(!trace)return "requirement";
|
|
1331
|
+
const value=type?.trim();
|
|
1332
|
+
if(value==="")return "requirement";
|
|
1333
|
+
return ["Requirement","System","Need","Source","Term","Test","Test plan"].includes(value)?value.toLowerCase():"record";
|
|
1334
|
+
}
|
|
1335
|
+
function deleteSelectedRecord(){
|
|
1336
|
+
if(!developMode()||state.editingCell)return;
|
|
1337
|
+
const id=selectedRequirementId(),row=id&&findCurrentRow(id);
|
|
1338
|
+
if(!row)return;
|
|
1339
|
+
const kind=recordKind(row.Type);
|
|
1340
|
+
if(kind==="system"){
|
|
1341
|
+
trace.openDeletion(id);
|
|
1342
|
+
return;
|
|
1343
|
+
}
|
|
1344
|
+
const name=kind==="requirement"?id:row.Name?.trim()||id;
|
|
1345
|
+
const commentCount=state.comments.filter(c=>c.requirementId===id).length;
|
|
1346
|
+
const links=(trace?.incomingChanges(id,null)??[]).filter(change=>rowId(change.row)!==id);
|
|
1347
|
+
const comments=commentCount?` and its ${commentCount} attached comment${commentCount===1?"":"s"}`:"";
|
|
1348
|
+
const affected=links.length
|
|
1349
|
+
?`\n\nThe following records reference ${id}. Confirm to remove these links as part of the deletion.\n`
|
|
1350
|
+
+links.map(({row,field})=>`${rowId(row)} · ${field}`).join("\n")
|
|
1351
|
+
:"";
|
|
1352
|
+
if(!confirm(`Delete ${kind} ${name}${comments}?${affected}`))return;
|
|
1353
|
+
deleteRecord(id,links);
|
|
1354
|
+
}
|
|
1355
|
+
function deleteRecord(id,links){
|
|
1356
|
+
const index=state.currentRows.findIndex(row=>rowId(row)===id);
|
|
1357
|
+
if(index<0)return;
|
|
1358
|
+
remember();
|
|
1359
|
+
for(const change of links)change.row[change.field]=change.value;
|
|
1360
|
+
state.currentRows.splice(index,1);
|
|
1361
|
+
state.comments=state.comments.filter(c=>c.requirementId!==id);
|
|
1362
|
+
updateDirty();
|
|
1363
|
+
render();
|
|
1364
|
+
}
|
|
1365
|
+
function fitCompactEditor(){
|
|
1366
|
+
const textarea=tableBody.querySelector(".cell-editor-compact textarea");
|
|
1367
|
+
if(!textarea)return;
|
|
1368
|
+
textarea.style.height="auto";
|
|
1369
|
+
textarea.style.height=`${textarea.scrollHeight+2}px`;
|
|
1370
|
+
}
|
|
1371
|
+
function positionCellEditor(){
|
|
1372
|
+
if(!state.editingCell?.expanded){fitCompactEditor();return;}
|
|
1373
|
+
const form=tableBody.querySelector(".cell-editor-expanded");
|
|
1374
|
+
if(!form)return;
|
|
1375
|
+
const cell=form.closest("[data-grid-cell]").getBoundingClientRect();
|
|
1376
|
+
const bounds=$(".table-wrap").getBoundingClientRect(),margin=8;
|
|
1377
|
+
const leftEdge=Math.max(margin,bounds.left+margin);
|
|
1378
|
+
const rightEdge=Math.min(document.documentElement.clientWidth,bounds.right)-margin;
|
|
1379
|
+
const width=Math.max(0,Math.min(360,rightEdge-leftEdge));
|
|
1380
|
+
form.style.width=`${width}px`;
|
|
1381
|
+
fitCompactEditor();
|
|
1382
|
+
form.style.left=`${Math.max(leftEdge,Math.min(cell.left,rightEdge-width))}px`;
|
|
1383
|
+
form.style.top=`${Math.max(margin,Math.min(cell.top+margin,innerHeight-form.offsetHeight-margin))}px`;
|
|
1384
|
+
}
|
|
1385
|
+
window.addEventListener("resize",()=>{if(trace?.columnLayout())renderLayout();else positionCellEditor();});
|
|
1386
|
+
window.addEventListener("scroll",positionCellEditor);
|
|
1387
|
+
$(".table-wrap").addEventListener("scroll",positionCellEditor);
|
|
1388
|
+
for(const type of ["click","keyup"])document.addEventListener(type,event=>{
|
|
1389
|
+
if(state.editingCell?.source.multiple&&event.target.matches("[data-cell-editor] textarea"))updateCellSuggestions(event.target.form);
|
|
1390
|
+
});
|
|
1391
|
+
function updateCellSuggestions(form){
|
|
1392
|
+
const list=form.querySelector(".cell-suggestions");
|
|
1393
|
+
const textarea=form.querySelector("textarea");
|
|
1394
|
+
const {source}=state.editingCell;
|
|
1395
|
+
const matches=matchSuggestions(source,textarea.value,textarea.selectionStart);
|
|
1396
|
+
list.replaceChildren(...matches.map(({value,detail})=>{
|
|
1397
|
+
const button=document.createElement("button");
|
|
1398
|
+
button.type="button";
|
|
1399
|
+
button.tabIndex=-1;
|
|
1400
|
+
const name=document.createElement("span");
|
|
1401
|
+
name.textContent=value;
|
|
1402
|
+
button.append(name);
|
|
1403
|
+
if(detail){
|
|
1404
|
+
const note=document.createElement("small");
|
|
1405
|
+
note.className="suggestion-detail";
|
|
1406
|
+
note.textContent=detail;
|
|
1407
|
+
button.append(note);
|
|
1408
|
+
button.title=detail;
|
|
1409
|
+
button.setAttribute("aria-description",detail);
|
|
1410
|
+
}
|
|
1411
|
+
button.addEventListener("click",()=>{
|
|
1412
|
+
const chosen=chooseSuggestion(source,textarea.value,textarea.selectionStart,value);
|
|
1413
|
+
textarea.value=chosen.text;
|
|
1414
|
+
if(chosen.commit)return applyCellEdit(form);
|
|
1415
|
+
state.editingCell.draft=chosen.text;
|
|
1416
|
+
textarea.setSelectionRange(chosen.caret,chosen.caret);
|
|
1417
|
+
textarea.focus();
|
|
1418
|
+
updateCellSuggestions(form);
|
|
1419
|
+
});
|
|
1420
|
+
return button;
|
|
1421
|
+
}));
|
|
1422
|
+
list.hidden=!matches.length;
|
|
1423
|
+
positionCellEditor();
|
|
1424
|
+
}
|
|
1425
|
+
function startCellEdit(cell,{selection="start",initialText}={}){
|
|
1426
|
+
const rid=cell?.closest("tr")?.dataset.rowId,column=cell?.dataset.column;
|
|
1427
|
+
if(!developMode()||state.editingCell||column===data.meta.idColumn||!data.source.new.headers.includes(column)||(rid!==""&&!findCurrentRow(rid)))return;
|
|
1428
|
+
if(booleanApplies(column,trace?.recordType(rid)))return (initialText===undefined||initialText===" ")&&toggleBooleanCell(cell);
|
|
1429
|
+
rangeSelection=null;
|
|
1430
|
+
paintSelection();
|
|
1431
|
+
const expanded=cell.getBoundingClientRect().width<220;
|
|
1432
|
+
const source=suggestionSource(trace?.valueRule(column),state.currentRows,column);
|
|
1433
|
+
state.editingCell={rid,column,expanded,source};
|
|
1434
|
+
const editor=renderCellEditor(rid,visibleColumns()[+cell.dataset.columnIndex],findCurrentRow(rid)?.[column]??"",expanded,source.defined);
|
|
1435
|
+
if(expanded)cell.insertAdjacentHTML("beforeend",editor);
|
|
1436
|
+
else cell.innerHTML=editor;
|
|
1437
|
+
ensureCellVisible(cell);
|
|
1438
|
+
positionCellEditor();
|
|
1439
|
+
const textarea=cell.querySelector("textarea");
|
|
1440
|
+
textarea.focus({preventScroll:true});
|
|
1441
|
+
if(initialText!==undefined){
|
|
1442
|
+
textarea.value=initialText;
|
|
1443
|
+
state.editingCell.draft=initialText;
|
|
1444
|
+
}else{
|
|
1445
|
+
if(selection==="auto"){
|
|
1446
|
+
const name=column.trim().toLowerCase();
|
|
1447
|
+
const categorical=["category","priority","verification method","type"].includes(name);
|
|
1448
|
+
const narrative=["requirement","requirement text","acceptance criteria","rationale"].includes(name)
|
|
1449
|
+
||column===state.qualityReview.settings.requirement_column;
|
|
1450
|
+
selection=!narrative&&(categorical||(expanded&&source.items.length))?"all":"end";
|
|
1451
|
+
}
|
|
1452
|
+
if(selection==="all")textarea.select();
|
|
1453
|
+
else if(selection==="end"){
|
|
1454
|
+
const end=textarea.value.length;
|
|
1455
|
+
textarea.setSelectionRange(end,end);
|
|
1456
|
+
}
|
|
1457
|
+
}
|
|
1458
|
+
updateCellSuggestions(textarea.form);
|
|
1459
|
+
return true;
|
|
1460
|
+
}
|
|
1461
|
+
function cancelCellEdit(){
|
|
1462
|
+
const {rid,column}=state.editingCell;
|
|
1463
|
+
state.editingCell=null;
|
|
1464
|
+
render();
|
|
1465
|
+
focusRequirement(rid,column);
|
|
1466
|
+
}
|
|
1467
|
+
function applyCellEdit(form,next,continueAtEntry=false){
|
|
1468
|
+
const sameRow=next?.row===cellPosition(form.closest("[data-grid-cell]")).row;
|
|
1469
|
+
const nextId=next&&grid.display[next.row]?.id;
|
|
1470
|
+
const nextColumn=next&&visibleColumns()[next.column]?.name;
|
|
1471
|
+
let id=form.dataset.rowId;
|
|
1472
|
+
const column=form.dataset.column,value=form.querySelector("textarea").value.replace(/\r\n?/g,"\n").trimEnd();
|
|
1473
|
+
const row=findCurrentRow(id);
|
|
1474
|
+
let changes=null;
|
|
1475
|
+
if(id===""&&value){
|
|
1476
|
+
remember();
|
|
1477
|
+
id=nextRecordId();
|
|
1478
|
+
const added=newRequirement(id);
|
|
1479
|
+
trace?.allocate(added);
|
|
1480
|
+
added[column]=value;
|
|
1481
|
+
state.currentRows.push(added);
|
|
1482
|
+
}else if(row&&String(row[column]??"")!==value){
|
|
1483
|
+
const before=String(row[column]??"");
|
|
1484
|
+
remember();
|
|
1485
|
+
row[column]=value;
|
|
1486
|
+
trace?.followValueRename(row,column,before);
|
|
1487
|
+
changes=changedRecords(state.undo.at(-1).rows,state.currentRows,rowId);
|
|
1488
|
+
}else if(row){
|
|
1489
|
+
changes=[];
|
|
1490
|
+
}
|
|
1491
|
+
if(form.dataset.rowId==="")changes=null;
|
|
1492
|
+
// The edited row always redraws to close its editor.
|
|
1493
|
+
else if(changes&&!changes.some(change=>change.id===id))changes.push({index:state.currentRows.indexOf(row),id,columns:new Set()});
|
|
1494
|
+
state.editingCell=null;
|
|
1495
|
+
updateDirty();
|
|
1496
|
+
renderChanges(changes);
|
|
1497
|
+
if(next&&focusRequirement(sameRow?id:nextId,nextColumn))return;
|
|
1498
|
+
if(continueAtEntry&&form.dataset.rowId===""&&id!==""&&focusRequirement("",column))return;
|
|
1499
|
+
if(!focusRequirement(id,column))restoreSelectedCell();
|
|
1500
|
+
}
|
|
1501
|
+
function exportedComments(id,comments){return comments.filter(c=>c.requirementId===id).sort((a,b)=>a.created.localeCompare(b.created)).map(c=>({column:c.column,initials:c.initials,created:c.created,modified:c.modified||null,text:c.text}));}function commentsText(list){return list.map(c=>`[${c.modified||c.created}] [${c.initials}] [${c.column}]\n${c.text}`).join("\n\n---\n\n");}function makeCsv(snapshot){const headers=[...data.source.new.headers],commentColumn=data.options.commentsColumn||"Comments";if(data.options.commentsEnabled&&headers.includes(commentColumn)){alert(`Cannot export comments because the CSV already has a ${commentColumn} column.`);return null;}if(data.options.commentsEnabled)headers.push(commentColumn);const rows=snapshot.rows.map(source=>{const row={...source};if(data.options.commentsEnabled){const list=exportedComments(rowId(source),snapshot.comments);row[commentColumn]=data.options.commentsFormat==="text"?commentsText(list):JSON.stringify(list);}return row;});return csvText(headers,rows,data.options.csvDelimiter||",");}
|
|
1502
|
+
function currentSnapshot(){
|
|
1503
|
+
return {rows:cloneValue(state.currentRows),comments:cloneValue(state.comments),decisions:cloneValue(state.decisions),qualityReview:cloneValue(state.qualityReview)};
|
|
1504
|
+
}
|
|
1505
|
+
let csvHandle=null,writingCsv=false,autosaveTimer=null;
|
|
1506
|
+
function scheduleAutosave(){
|
|
1507
|
+
clearTimeout(autosaveTimer);
|
|
1508
|
+
if(!developMode()||!$("#autosave").checked)return;
|
|
1509
|
+
if(csvHandle&&(state.requirementsDirty||state.commentsDirty)&&!writingCsv){
|
|
1510
|
+
autosaveTimer=setTimeout(()=>{if(!state.editingCell)saveCsv(false,true);},1200);
|
|
1511
|
+
}
|
|
1512
|
+
}
|
|
1513
|
+
function markSaved(snapshot,message){
|
|
1514
|
+
state.savedRows=snapshot.rows;
|
|
1515
|
+
state.savedComments=snapshot.comments;
|
|
1516
|
+
state.savedDecisions=snapshot.decisions;
|
|
1517
|
+
updateDirty();
|
|
1518
|
+
if(state.compareWith==="saved"&&!state.editingCell)render();
|
|
1519
|
+
$("#save-status").textContent=message;
|
|
1520
|
+
}
|
|
1521
|
+
async function saveCsv(saveAs=false,automatic=false){
|
|
1522
|
+
if(writingCsv||!developMode())return;
|
|
1523
|
+
if(state.editingCell){
|
|
1524
|
+
if(!automatic)$("#save-status").textContent="Apply or cancel the cell edit before saving";
|
|
1525
|
+
return;
|
|
1526
|
+
}
|
|
1527
|
+
clearTimeout(autosaveTimer);
|
|
1528
|
+
writingCsv=true;
|
|
1529
|
+
let writer,succeeded=false;
|
|
1530
|
+
try{
|
|
1531
|
+
const filename=data.meta.newFilename||`${data.meta.baseFilename}.csv`;
|
|
1532
|
+
let handle=saveAs?null:csvHandle;
|
|
1533
|
+
if(!handle&&typeof window.showSaveFilePicker==="function"){
|
|
1534
|
+
try{
|
|
1535
|
+
handle=await window.showSaveFilePicker({suggestedName:filename,types:[{description:"CSV file",accept:{"text/csv":[".csv"]}}]});
|
|
1536
|
+
}catch(error){
|
|
1537
|
+
if(error.name==="AbortError")return;
|
|
1538
|
+
if(!["SecurityError","NotAllowedError"].includes(error.name))throw error;
|
|
1539
|
+
}
|
|
1540
|
+
}
|
|
1541
|
+
const snapshot=currentSnapshot(),source=makeCsv(snapshot);
|
|
1542
|
+
if(source===null)return;
|
|
1543
|
+
const blob=new Blob([source],{type:"text/csv;charset=utf-8"});
|
|
1544
|
+
if(handle){
|
|
1545
|
+
writer=await handle.createWritable();
|
|
1546
|
+
await writer.write(blob);
|
|
1547
|
+
await writer.close();
|
|
1548
|
+
csvHandle=handle;
|
|
1549
|
+
succeeded=true;
|
|
1550
|
+
markSaved(snapshot,`${automatic?"CSV autosaved":"CSV saved"} at ${new Date().toLocaleTimeString()}`);
|
|
1551
|
+
}else{
|
|
1552
|
+
downloadBlob(blob,filename);
|
|
1553
|
+
markSaved(snapshot,"CSV download initiated");
|
|
1554
|
+
}
|
|
1555
|
+
}catch(error){
|
|
1556
|
+
try{await writer?.abort();}catch{}
|
|
1557
|
+
if(automatic)csvHandle=null;
|
|
1558
|
+
$("#save-status").textContent=`CSV save failed: ${error.message}`;
|
|
1559
|
+
}finally{
|
|
1560
|
+
writingCsv=false;
|
|
1561
|
+
if(state.dirty&&csvHandle&&$("#autosave").checked&&!state.editingCell&&succeeded)scheduleAutosave();
|
|
1562
|
+
}
|
|
1563
|
+
}
|
|
1564
|
+
$("#autosave").addEventListener("change",()=>{scheduleAutosave();draftChanged();});
|
|
1565
|
+
function prepareReviewCopy(clone,embedded,withChanges){
|
|
1566
|
+
const rows=byId(embedded.source.new.rows);
|
|
1567
|
+
const counts={added:0,removed:0,changed:0,unchanged:0};
|
|
1568
|
+
embedded.meta={...embedded.meta,documentMode:"review",mode:"snapshot",
|
|
1569
|
+
generated:localTimestamp(),oldFilename:null,counts};
|
|
1570
|
+
embedded.options={...embedded.options,reviewerInitials:""};
|
|
1571
|
+
embedded.columns=embedded.columns.filter(column=>!column.oldOnly)
|
|
1572
|
+
.map(column=>({...column,newOnly:false}));
|
|
1573
|
+
embedded.comments=embedded.comments.filter(comment=>rows.has(comment.requirementId));
|
|
1574
|
+
embedded.qualityReview.dismissals=embedded.qualityReview.dismissals.filter(({id,column,value})=>
|
|
1575
|
+
rows.get(id)?.[column]===value);
|
|
1576
|
+
|
|
1577
|
+
if(withChanges){
|
|
1578
|
+
embedded.meta.mode="diff";
|
|
1579
|
+
embedded.meta.oldFilename="Last saved version";
|
|
1580
|
+
Object.assign(embedded.options,{reviewComparison:true,initialChangesOnly:true,
|
|
1581
|
+
includeUnchanged:true,initialView:state.view});
|
|
1582
|
+
embedded.source.old={headers:embedded.source.new.headers,rows:state.savedRows};
|
|
1583
|
+
embedded.diffStatus=diffStatuses(comparisonSource("saved"),{includeMoves:true});
|
|
1584
|
+
for(const status of Object.values(embedded.diffStatus))counts[status]++;
|
|
1585
|
+
const retained=new Set(embedded.comments.map(comment=>comment.id));
|
|
1586
|
+
for(const comment of state.savedComments){
|
|
1587
|
+
if(embedded.diffStatus[comment.requirementId]==="removed"&&!retained.has(comment.id)){
|
|
1588
|
+
embedded.comments.push(comment);
|
|
1589
|
+
}
|
|
1590
|
+
}
|
|
1591
|
+
}else{
|
|
1592
|
+
counts.unchanged=rows.size;
|
|
1593
|
+
embedded.meta.ignoredColumns=[];
|
|
1594
|
+
embedded.source.old=null;
|
|
1595
|
+
delete embedded.diffStatus;
|
|
1596
|
+
}
|
|
1597
|
+
const badge=clone.querySelector("#document-mode");
|
|
1598
|
+
badge.classList.replace("develop","review");
|
|
1599
|
+
badge.textContent="Review mode";
|
|
1600
|
+
const comparison=withChanges?" · Compared with last save":"";
|
|
1601
|
+
const description=`Source: ${embedded.meta.newFilename}${comparison} · Generated ${embedded.meta.generated}`;
|
|
1602
|
+
clone.querySelector("#metadata").textContent=description;
|
|
1603
|
+
clone.querySelector(".report-info summary").title=description;
|
|
1604
|
+
clone.querySelector(".print-details").textContent=description;
|
|
1605
|
+
clone.querySelector(".report-info .summary").replaceChildren();
|
|
1606
|
+
clone.querySelector("#reviewer-label").textContent="Set initials";
|
|
1607
|
+
clone.querySelector("#reviewer-details summary").setAttribute("aria-label","Set reviewer initials");
|
|
1608
|
+
clone.querySelectorAll(".develop-only,.diff-only").forEach(element=>element.hidden=true);
|
|
1609
|
+
}
|
|
1610
|
+
function saveReportCopy({forReview=false,withChanges=false}={}){
|
|
1611
|
+
if(writingCsv||(forReview&&!developMode()))return;
|
|
1612
|
+
if(state.editingCell){
|
|
1613
|
+
$("#save-status").textContent="Apply or cancel the cell edit before saving";
|
|
1614
|
+
return;
|
|
1615
|
+
}
|
|
1616
|
+
const initials=forReview?"":reviewerInitials();
|
|
1617
|
+
let token="";
|
|
1618
|
+
if(!forReview&&data.options.commentsEnabled){
|
|
1619
|
+
if(!validInitials(initials)){
|
|
1620
|
+
alert("Enter 1–16 reviewer initials before saving.");
|
|
1621
|
+
focusReviewerInitials();
|
|
1622
|
+
return;
|
|
1623
|
+
}
|
|
1624
|
+
token=filenameInitials(initials);
|
|
1625
|
+
if(!token){
|
|
1626
|
+
alert("Enter initials containing at least one ASCII letter or digit for the filename.");
|
|
1627
|
+
return;
|
|
1628
|
+
}
|
|
1629
|
+
persistReviewerInitials();
|
|
1630
|
+
data.options.reviewerInitials=initials;
|
|
1631
|
+
}
|
|
1632
|
+
|
|
1633
|
+
const clone=document.documentElement.cloneNode(true),snapshot=currentSnapshot();
|
|
1634
|
+
const embedded={...data,comments:snapshot.comments,...(data.package&&{decisions:snapshot.decisions}),qualityReview:snapshot.qualityReview,
|
|
1635
|
+
source:{...data.source,new:{...data.source.new,rows:snapshot.rows}}};
|
|
1636
|
+
delete embedded.rows;
|
|
1637
|
+
if(forReview)prepareReviewCopy(clone,embedded,withChanges);
|
|
1638
|
+
else if(data.meta.mode==="diff")embedded.diffStatus=diffStatuses(comparisonSource("old"),{
|
|
1639
|
+
includeMoves:data.options.reviewComparison,includeUnchanged:data.options.includeUnchanged});
|
|
1640
|
+
clone.querySelector("#reqtable-data").textContent=safeJson(embedded);
|
|
1641
|
+
|
|
1642
|
+
for(const id of ["requirements-body","heading-row","filter-row","column-widths","column-list",
|
|
1643
|
+
"active-filter-list","table-context-menu","row-drag-preview","comment-list","quality-findings",
|
|
1644
|
+
"quality-count","quality-dismiss-description","quick-comment","comment-hover","value-filter-popover",
|
|
1645
|
+
"finding-popover-title","finding-popover-list","finding-popover-actions",
|
|
1646
|
+
"dirty-details","dirty-announcement","save-status","draft-message"]){
|
|
1647
|
+
clone.querySelector("#"+id).replaceChildren();
|
|
1648
|
+
}
|
|
1649
|
+
for(const id of ["table-context-menu","row-drag-preview","quality-panel","quick-comment","comment-hover",
|
|
1650
|
+
"value-filter-popover","finding-popover","review-panel","dirty-indicator","draft-banner"]){
|
|
1651
|
+
clone.querySelector("#"+id).hidden=true;
|
|
1652
|
+
}
|
|
1653
|
+
trace?.clearCopy(clone);
|
|
1654
|
+
if(data.package)packageClearCopy(clone);
|
|
1655
|
+
clone.querySelectorAll("details[open],dialog[open]").forEach(element=>element.removeAttribute("open"));
|
|
1656
|
+
clone.querySelector("#quality-dismiss-reason").replaceChildren();
|
|
1657
|
+
clone.querySelector("#reviewer-initials").setAttribute("value",initials);
|
|
1658
|
+
for(const option of clone.querySelector("#keyboard-mode").options){
|
|
1659
|
+
option.toggleAttribute("selected",option.value===keyboardMode.value);
|
|
1660
|
+
}
|
|
1661
|
+
|
|
1662
|
+
const kind=forReview?(withChanges?"changes-for-review":"for-review"):developMode()?"developed":"reviewed";
|
|
1663
|
+
const suffix=token?`-${token}`:"";
|
|
1664
|
+
const filename=`${data.meta.baseFilename}-${kind}${suffix}-${filenameTimestamp()}.html`;
|
|
1665
|
+
downloadBlob(new Blob(['<!doctype html>\n'+clone.outerHTML],{type:"text/html;charset=utf-8"}),filename);
|
|
1666
|
+
if(forReview){
|
|
1667
|
+
$("#save-status").textContent="Review copy download initiated";
|
|
1668
|
+
}else{
|
|
1669
|
+
state.savedQualityReview=snapshot.qualityReview;
|
|
1670
|
+
markSaved(snapshot,`Report download initiated at ${new Date().toLocaleTimeString()}`);
|
|
1671
|
+
}
|
|
1672
|
+
}
|
|
1673
|
+
$("#revert-selected-cell").addEventListener("click",revertSelectedCell);
|
|
1674
|
+
$("#restore-deleted-requirement").addEventListener("click",restoreDeletedRequirement);
|
|
1675
|
+
$("#review-comparison").addEventListener("click",()=>{
|
|
1676
|
+
setCompareWith(state.compareWith===null?"old":null);
|
|
1677
|
+
render();
|
|
1678
|
+
});
|
|
1679
|
+
const tableContextMenu=$("#table-context-menu");
|
|
1680
|
+
let contextCell=null;
|
|
1681
|
+
function closeTableContext(restoreFocus=false){
|
|
1682
|
+
tableContextMenu.hidden=true;
|
|
1683
|
+
if(restoreFocus&&contextCell?.isConnected)contextCell.focus({preventScroll:true});
|
|
1684
|
+
contextCell=null;
|
|
1685
|
+
}
|
|
1686
|
+
function openTableContext(cell,x,y){
|
|
1687
|
+
closeHeaderPopups();
|
|
1688
|
+
closeQuick();
|
|
1689
|
+
closeValueFilter();
|
|
1690
|
+
focusGridCell(+cell.dataset.rowIndex,+cell.dataset.columnIndex);
|
|
1691
|
+
const index=state.currentRows.findIndex(row=>rowId(row)===selectedRequirementId());
|
|
1692
|
+
const actions=[];
|
|
1693
|
+
if(index>=0){
|
|
1694
|
+
if(trace)actions.push("trace-selected-links");
|
|
1695
|
+
actions.push("add-above","add-below");
|
|
1696
|
+
if(index>0)actions.push("move-up");
|
|
1697
|
+
if(index<state.currentRows.length-1)actions.push("move-down");
|
|
1698
|
+
actions.push("delete-requirement");
|
|
1699
|
+
}else if(cell.parentElement.dataset.rowId===""){
|
|
1700
|
+
actions.push("add-end");
|
|
1701
|
+
}
|
|
1702
|
+
actions.push("revert-selected-cell","restore-deleted-requirement");
|
|
1703
|
+
tableContextMenu.replaceChildren();
|
|
1704
|
+
for(const id of actions){
|
|
1705
|
+
const action=document.getElementById(id);
|
|
1706
|
+
if(action.disabled||action.closest("[hidden]"))continue;
|
|
1707
|
+
const button=document.createElement("button");
|
|
1708
|
+
button.type="button";
|
|
1709
|
+
button.textContent=[...action.childNodes].filter(node=>!node.matches?.("kbd"))
|
|
1710
|
+
.map(node=>node.textContent).join("").trim();
|
|
1711
|
+
button.addEventListener("click",()=>{
|
|
1712
|
+
closeTableContext(true);
|
|
1713
|
+
action.click();
|
|
1714
|
+
});
|
|
1715
|
+
tableContextMenu.append(button);
|
|
1716
|
+
}
|
|
1717
|
+
if(!tableContextMenu.childElementCount)return;
|
|
1718
|
+
contextCell=cell;
|
|
1719
|
+
tableContextMenu.hidden=false;
|
|
1720
|
+
const {width,height}=tableContextMenu.getBoundingClientRect();
|
|
1721
|
+
tableContextMenu.style.left=`${Math.max(8,Math.min(x,innerWidth-width-8))}px`;
|
|
1722
|
+
tableContextMenu.style.top=`${Math.max(8,Math.min(y,innerHeight-height-8))}px`;
|
|
1723
|
+
tableContextMenu.firstElementChild.focus({preventScroll:true});
|
|
1724
|
+
}
|
|
1725
|
+
tableBody.addEventListener("contextmenu",event=>{
|
|
1726
|
+
const cell=event.target.closest("[data-grid-cell]");
|
|
1727
|
+
if(!developMode()||!cell||state.editingCell||event.target.closest("a"))return;
|
|
1728
|
+
event.preventDefault();
|
|
1729
|
+
openTableContext(cell,event.clientX,event.clientY);
|
|
1730
|
+
});
|
|
1731
|
+
tableBody.addEventListener("keydown",event=>{
|
|
1732
|
+
if(!developMode()||state.editingCell||!event.target.matches("[data-grid-cell]"))return;
|
|
1733
|
+
if(event.key!=="ContextMenu"&&!(event.shiftKey&&event.key==="F10"))return;
|
|
1734
|
+
event.preventDefault();
|
|
1735
|
+
const bounds=event.target.getBoundingClientRect();
|
|
1736
|
+
openTableContext(event.target,bounds.left,bounds.bottom);
|
|
1737
|
+
});
|
|
1738
|
+
tableContextMenu.addEventListener("keydown",event=>{
|
|
1739
|
+
const items=[...tableContextMenu.children],index=items.indexOf(event.target);
|
|
1740
|
+
if(event.key==="Escape")closeTableContext(true);
|
|
1741
|
+
else if(event.key==="ArrowDown")items[(index+1)%items.length].focus();
|
|
1742
|
+
else if(event.key==="ArrowUp")items[(index+items.length-1)%items.length].focus();
|
|
1743
|
+
else return;
|
|
1744
|
+
event.preventDefault();
|
|
1745
|
+
event.stopPropagation();
|
|
1746
|
+
});
|
|
1747
|
+
document.addEventListener("pointerdown",event=>{
|
|
1748
|
+
if(!tableContextMenu.hidden&&!tableContextMenu.contains(event.target))closeTableContext();
|
|
1749
|
+
});
|
|
1750
|
+
document.addEventListener("focusin",event=>{
|
|
1751
|
+
if(!tableContextMenu.hidden&&!tableContextMenu.contains(event.target))closeTableContext();
|
|
1752
|
+
});
|
|
1753
|
+
$(".table-wrap").addEventListener("scroll",()=>closeTableContext());
|
|
1754
|
+
|
|
1755
|
+
let cellDrag=null,suppressClick=false;
|
|
1756
|
+
const DRAG_IGNORED="textarea,form,a,button:not(.glossary-link),.row-grip,[data-resize],.trace-marker,.quality-marker,[data-bool-toggle]";
|
|
1757
|
+
function scrollEdges(){
|
|
1758
|
+
const box=tableScroller()===tableWrap?tableWrap.getBoundingClientRect():{top:0,bottom:innerHeight};
|
|
1759
|
+
return {top:Math.max(0,box.top,table.tHead.getBoundingClientRect().bottom),bottom:Math.min(innerHeight,box.bottom)};
|
|
1760
|
+
}
|
|
1761
|
+
function pointCell({x,y}){
|
|
1762
|
+
const {top,bottom}=scrollEdges(),box=tableWrap.getBoundingClientRect();
|
|
1763
|
+
const hit=document.elementFromPoint(Math.max(box.left+1,Math.min(box.right-2,x)),Math.max(top+1,Math.min(bottom-2,y)));
|
|
1764
|
+
const cell=hit?.closest("[data-grid-cell]");
|
|
1765
|
+
if(cell&&tableBody.contains(cell))return cellPosition(cell);
|
|
1766
|
+
const row=hit?.closest("tr[data-row-index]");
|
|
1767
|
+
return row&&tableBody.contains(row)?{row:+row.dataset.rowIndex,column:rangeSelection?.extent.column??cellDrag.anchor.column}:null;
|
|
1768
|
+
}
|
|
1769
|
+
function dragSelectTo(){
|
|
1770
|
+
const to=pointCell(cellDrag),from=rangeSelection?.extent;
|
|
1771
|
+
if(to&&!(from&&from.row===to.row&&from.column===to.column))extendSelection(to);
|
|
1772
|
+
}
|
|
1773
|
+
function dragTick(){
|
|
1774
|
+
if(!cellDrag)return;
|
|
1775
|
+
const {top,bottom}=scrollEdges(),speed=edgeScrollSpeed(cellDrag.y,top,bottom);
|
|
1776
|
+
if(speed){tableScroller().scrollTop+=speed;updateWindow();dragSelectTo();}
|
|
1777
|
+
cellDrag.frame=requestAnimationFrame(dragTick);
|
|
1778
|
+
}
|
|
1779
|
+
tableBody.addEventListener("pointerdown",event=>{
|
|
1780
|
+
const cell=event.target.closest("[data-grid-cell]");
|
|
1781
|
+
if(!cell||event.button!==0||event.pointerType==="touch"||state.editingCell||event.target.closest(DRAG_IGNORED))return;
|
|
1782
|
+
if(event.shiftKey&&!event.target.closest("button"))event.preventDefault();
|
|
1783
|
+
cellDrag={pointerId:event.pointerId,anchor:cellPosition(cell),shift:event.shiftKey,x:event.clientX,y:event.clientY,moved:false,frame:0};
|
|
1784
|
+
});
|
|
1785
|
+
tableBody.addEventListener("pointermove",event=>{
|
|
1786
|
+
if(cellDrag?.pointerId!==event.pointerId)return;
|
|
1787
|
+
cellDrag.x=event.clientX;
|
|
1788
|
+
cellDrag.y=event.clientY;
|
|
1789
|
+
if(!cellDrag.moved){
|
|
1790
|
+
const at=pointCell(cellDrag);
|
|
1791
|
+
if(!at||(at.row===cellDrag.anchor.row&&at.column===cellDrag.anchor.column))return;
|
|
1792
|
+
cellDrag.moved=true;
|
|
1793
|
+
table.classList.add("selecting");
|
|
1794
|
+
getSelection().removeAllRanges();
|
|
1795
|
+
tableBody.setPointerCapture(event.pointerId);
|
|
1796
|
+
if(!cellDrag.shift)rangeSelection={anchor:cellDrag.anchor,extent:cellDrag.anchor,wholeRows:false};
|
|
1797
|
+
cellDrag.frame=requestAnimationFrame(dragTick);
|
|
1798
|
+
}
|
|
1799
|
+
dragSelectTo();
|
|
1800
|
+
});
|
|
1801
|
+
function finishCellDrag(event){
|
|
1802
|
+
if(cellDrag?.pointerId!==event.pointerId)return;
|
|
1803
|
+
const {moved,frame}=cellDrag;
|
|
1804
|
+
cancelAnimationFrame(frame);
|
|
1805
|
+
cellDrag=null;
|
|
1806
|
+
table.classList.remove("selecting");
|
|
1807
|
+
if(tableBody.hasPointerCapture(event.pointerId))tableBody.releasePointerCapture(event.pointerId);
|
|
1808
|
+
if(moved){suppressClick=true;setTimeout(()=>{suppressClick=false;});}
|
|
1809
|
+
}
|
|
1810
|
+
for(const type of ["pointerup","pointercancel","lostpointercapture"])tableBody.addEventListener(type,finishCellDrag);
|
|
1811
|
+
document.addEventListener("click",event=>{
|
|
1812
|
+
if(!suppressClick)return;
|
|
1813
|
+
suppressClick=false;
|
|
1814
|
+
event.preventDefault();
|
|
1815
|
+
event.stopImmediatePropagation();
|
|
1816
|
+
},true);
|
|
1817
|
+
function gridClipboardEvent(){
|
|
1818
|
+
// Chromium can target a paragraph inside the focused cell after a mouse click.
|
|
1819
|
+
// Check focus instead so text editors and other controls keep native clipboard behavior.
|
|
1820
|
+
const cell=document.activeElement;
|
|
1821
|
+
return !state.editingCell&&cell?.matches("[data-grid-cell]")&&tableBody.contains(cell);
|
|
1822
|
+
}
|
|
1823
|
+
function selectionText(){
|
|
1824
|
+
const {top,bottom,left,right}=selectionBounds();
|
|
1825
|
+
const columns=visibleColumns().slice(left,right+1);
|
|
1826
|
+
const rows=grid.display.slice(top,bottom+1).filter(row=>row.id!=="");
|
|
1827
|
+
if(!rows.length||!columns.length)return null;
|
|
1828
|
+
return rows.map(row=>columns.map(column=>csvField(valueFor(row,column.name),"\t")).join("\t")).join("\r\n");
|
|
1829
|
+
}
|
|
1830
|
+
function copySelection(event){
|
|
1831
|
+
if(!gridClipboardEvent()||!event.clipboardData)return;
|
|
1832
|
+
const text=selectionText();
|
|
1833
|
+
if(text===null)return;
|
|
1834
|
+
event.preventDefault();
|
|
1835
|
+
event.clipboardData.setData("text/plain",text);
|
|
1836
|
+
}
|
|
1837
|
+
function parseClipboardBlock(text){
|
|
1838
|
+
const rows=[];
|
|
1839
|
+
let row=[],value="",quoted=false,closedQuote=false;
|
|
1840
|
+
for(let i=0;i<text.length;i++){
|
|
1841
|
+
const char=text[i];
|
|
1842
|
+
if(quoted){
|
|
1843
|
+
if(char==='"'&&text[i+1]==='"'){value+='"';i++;}
|
|
1844
|
+
else if(char==='"'){quoted=false;closedQuote=true;}
|
|
1845
|
+
else value+=char;
|
|
1846
|
+
}else if(char==="\t"||char==="\n"||char==="\r"){
|
|
1847
|
+
row.push(value);
|
|
1848
|
+
value="";
|
|
1849
|
+
closedQuote=false;
|
|
1850
|
+
if(char!=="\t"){
|
|
1851
|
+
rows.push(row);
|
|
1852
|
+
row=[];
|
|
1853
|
+
if(char==="\r"&&text[i+1]==="\n")i++;
|
|
1854
|
+
}
|
|
1855
|
+
}else if(closedQuote){
|
|
1856
|
+
throw new Error("Unexpected text after a quoted clipboard value.");
|
|
1857
|
+
}else if(char==='"'&&value===""){
|
|
1858
|
+
quoted=true;
|
|
1859
|
+
}else value+=char;
|
|
1860
|
+
}
|
|
1861
|
+
if(quoted)throw new Error("A quoted clipboard value is incomplete.");
|
|
1862
|
+
if(row.length||value||closedQuote||!rows.length)rows.push([...row,value]);
|
|
1863
|
+
return rows;
|
|
1864
|
+
}
|
|
1865
|
+
function pasteSelection(event){
|
|
1866
|
+
if(!developMode()||!gridClipboardEvent()||!event.clipboardData?.types.includes("text/plain"))return;
|
|
1867
|
+
event.preventDefault();
|
|
1868
|
+
applyPasteText(event.clipboardData.getData("text/plain"));
|
|
1869
|
+
}
|
|
1870
|
+
function applyPasteText(text){
|
|
1871
|
+
let block;
|
|
1872
|
+
try{block=parseClipboardBlock(text);}
|
|
1873
|
+
catch(error){alert(error.message);return;}
|
|
1874
|
+
const {row:startRow,column:startColumn}=state.focus;
|
|
1875
|
+
const columns=visibleColumns(),rows=grid.display,current=byId(state.currentRows);
|
|
1876
|
+
const changes=[];
|
|
1877
|
+
for(const [r,values] of block.entries()){
|
|
1878
|
+
const row=current.get(rows[startRow+r]?.id);
|
|
1879
|
+
if(!row){alert(`Cannot paste into display row ${startRow+r+1}. Select an existing record.`);return;}
|
|
1880
|
+
for(const [c,text] of values.entries()){
|
|
1881
|
+
const column=columns[startColumn+c]?.name;
|
|
1882
|
+
if(!column||column===data.meta.idColumn||!data.source.new.headers.includes(column)){
|
|
1883
|
+
alert(`Cannot paste into ${column??"a column beyond the table"}. Select editable columns.`);
|
|
1884
|
+
return;
|
|
1885
|
+
}
|
|
1886
|
+
const value=text.replace(/\r\n?/g,"\n").trimEnd();
|
|
1887
|
+
if(row[column]!==value)changes.push({row,column,value});
|
|
1888
|
+
}
|
|
1889
|
+
}
|
|
1890
|
+
if(!changes.length)return;
|
|
1891
|
+
const id=rows[startRow].id,column=columns[startColumn].name;
|
|
1892
|
+
remember();
|
|
1893
|
+
for(const change of changes)change.row[change.column]=change.value;
|
|
1894
|
+
updateDirty();
|
|
1895
|
+
render();
|
|
1896
|
+
if(!focusRequirement(id,column))restoreSelectedCell();
|
|
1897
|
+
}
|
|
1898
|
+
function clearSelectedCells(){
|
|
1899
|
+
if(!developMode()||state.editingCell)return;
|
|
1900
|
+
const {top,bottom,left,right}=selectionBounds();
|
|
1901
|
+
const columns=visibleColumns().slice(left,right+1),rows=grid.display.slice(top,bottom+1),current=byId(state.currentRows);
|
|
1902
|
+
const editable=columns.map(column=>column.name).filter(name=>name!==data.meta.idColumn&&data.source.new.headers.includes(name));
|
|
1903
|
+
const changes=[];
|
|
1904
|
+
for(const source of rows){
|
|
1905
|
+
const row=current.get(source.id);
|
|
1906
|
+
if(!row)continue;
|
|
1907
|
+
for(const name of editable)if(String(row[name]??"")!=="")changes.push({row,name});
|
|
1908
|
+
}
|
|
1909
|
+
if(!changes.length)return;
|
|
1910
|
+
remember();
|
|
1911
|
+
for(const {row,name} of changes)row[name]="";
|
|
1912
|
+
updateDirty();
|
|
1913
|
+
render();
|
|
1914
|
+
requestAnimationFrame(()=>focusGridCell(state.focus.row,state.focus.column,true));
|
|
1915
|
+
}
|
|
1916
|
+
function syncClipboardActions(){
|
|
1917
|
+
const disabled=!!state.editingCell||!grid.display.length;
|
|
1918
|
+
$("#copy-cells").disabled=disabled;
|
|
1919
|
+
for(const id of ["paste-cells","clear-cells"])$("#"+id).disabled=disabled||!developMode();
|
|
1920
|
+
}
|
|
1921
|
+
$("#copy-cells").addEventListener("click",async()=>{
|
|
1922
|
+
if(state.editingCell)return;
|
|
1923
|
+
const text=selectionText();
|
|
1924
|
+
focusGridCell(state.focus.row,state.focus.column,true);
|
|
1925
|
+
if(text===null)return;
|
|
1926
|
+
try{await navigator.clipboard.writeText(text);return;}catch{}
|
|
1927
|
+
const scratch=document.createElement("textarea");
|
|
1928
|
+
scratch.value=text;
|
|
1929
|
+
scratch.style.cssText="position:fixed;opacity:0;pointer-events:none";
|
|
1930
|
+
document.body.append(scratch);
|
|
1931
|
+
scratch.select();
|
|
1932
|
+
const copied=document.execCommand("copy");
|
|
1933
|
+
scratch.remove();
|
|
1934
|
+
focusGridCell(state.focus.row,state.focus.column,true);
|
|
1935
|
+
if(!copied)$("#save-status").textContent="Copy from the menu needs clipboard permission; use Cmd/Ctrl+C";
|
|
1936
|
+
});
|
|
1937
|
+
$("#paste-cells").addEventListener("click",async()=>{
|
|
1938
|
+
if(state.editingCell)return;
|
|
1939
|
+
let text;
|
|
1940
|
+
try{text=await navigator.clipboard.readText();}
|
|
1941
|
+
catch{$("#save-status").textContent="Paste from the menu needs clipboard permission; use Cmd/Ctrl+V";return;}
|
|
1942
|
+
$("#save-status").textContent="";
|
|
1943
|
+
applyPasteText(text);
|
|
1944
|
+
});
|
|
1945
|
+
$("#clear-cells").addEventListener("click",clearSelectedCells);
|
|
1946
|
+
$("#edit-menu").addEventListener("toggle",syncClipboardActions);
|
|
1947
|
+
tableBody.addEventListener("copy",copySelection);
|
|
1948
|
+
tableBody.addEventListener("paste",pasteSelection);
|
|
1949
|
+
|
|
1950
|
+
const rowDragPreview=$("#row-drag-preview");
|
|
1951
|
+
let rowDrag=null;
|
|
1952
|
+
function startRowDragPreview(){
|
|
1953
|
+
const row=findCurrentRow(rowDrag.id);
|
|
1954
|
+
const columns=data.source.new.headers.filter(name=>name!==data.meta.idColumn);
|
|
1955
|
+
const preferred=columns.find(name=>name.toLowerCase()==="requirement");
|
|
1956
|
+
const fallback=columns.find(name=>String(row?.[name]??"").trim());
|
|
1957
|
+
const summary=String(row?.[preferred]||row?.[fallback]||"").replace(/\s+/g," ").trim();
|
|
1958
|
+
const id=document.createElement("strong"),excerpt=document.createElement("span");
|
|
1959
|
+
id.textContent=rowDrag.ids.length>1?`${rowDrag.ids.length} requirements`:rowDrag.id;
|
|
1960
|
+
excerpt.textContent=rowDrag.ids.length>1
|
|
1961
|
+
?`${rowDrag.ids[0]}–${rowDrag.ids.at(-1)}`
|
|
1962
|
+
:summary.length>100?summary.slice(0,99)+"…":summary;
|
|
1963
|
+
rowDragPreview.replaceChildren(id,excerpt);
|
|
1964
|
+
rowDragPreview.hidden=false;
|
|
1965
|
+
rowDrag.shown=true;
|
|
1966
|
+
for(const row of tableBody.querySelectorAll("tr[data-row-id]"))if(rowDrag.ids.includes(row.dataset.rowId))row.classList.add("row-drag-source");
|
|
1967
|
+
}
|
|
1968
|
+
function showRowDrop(index){
|
|
1969
|
+
if(rowDrag.target===index)return;
|
|
1970
|
+
tableBody.querySelector(".drop-before")?.classList.remove("drop-before");
|
|
1971
|
+
rowDrag.target=index;
|
|
1972
|
+
if(index!==null)rowElement(index)?.classList.add("drop-before");
|
|
1973
|
+
}
|
|
1974
|
+
tableBody.addEventListener("pointerdown",event=>{
|
|
1975
|
+
const grip=event.target.closest(".row-grip");
|
|
1976
|
+
if(!grip||event.button!==0||rowDrag||!canDragRows()||state.editingCell)return;
|
|
1977
|
+
event.preventDefault();
|
|
1978
|
+
grip.setPointerCapture(event.pointerId);
|
|
1979
|
+
const source=grip.closest("tr");
|
|
1980
|
+
const {top,bottom}=selectionBounds();
|
|
1981
|
+
const index=+source.dataset.rowIndex;
|
|
1982
|
+
const ids=rangeSelection?.wholeRows&&index>=top&&index<=bottom
|
|
1983
|
+
?grid.display.slice(top,bottom+1).map(row=>row.id).filter(Boolean)
|
|
1984
|
+
:[source.dataset.rowId];
|
|
1985
|
+
rowDrag={pointerId:event.pointerId,id:source.dataset.rowId,ids,shown:false,
|
|
1986
|
+
x:event.clientX,y:event.clientY,target:null};
|
|
1987
|
+
});
|
|
1988
|
+
tableBody.addEventListener("pointermove",event=>{
|
|
1989
|
+
if(rowDrag?.pointerId!==event.pointerId)return;
|
|
1990
|
+
if(rowDragPreview.hidden){
|
|
1991
|
+
if(Math.hypot(event.clientX-rowDrag.x,event.clientY-rowDrag.y)<4)return;
|
|
1992
|
+
startRowDragPreview();
|
|
1993
|
+
}
|
|
1994
|
+
rowDragPreview.style.left=`${Math.max(8,Math.min(event.clientX+16,innerWidth-rowDragPreview.offsetWidth-8))}px`;
|
|
1995
|
+
rowDragPreview.style.top=`${Math.max(8,Math.min(event.clientY+16,innerHeight-rowDragPreview.offsetHeight-8))}px`;
|
|
1996
|
+
const viewport=tableWrap.getBoundingClientRect(),{top,bottom}=scrollEdges();
|
|
1997
|
+
if(event.clientX>=viewport.left&&event.clientX<=viewport.right)tableScroller().scrollTop+=edgeScrollSpeed(event.clientY,top,bottom);
|
|
1998
|
+
const row=document.elementFromPoint(event.clientX,event.clientY)?.closest("tr[data-row-id]");
|
|
1999
|
+
if(!row||!tableBody.contains(row)){showRowDrop(null);return;}
|
|
2000
|
+
const target=+row.dataset.rowIndex,bounds=row.getBoundingClientRect();
|
|
2001
|
+
// The space after a requirement is the same boundary as the top of the next row.
|
|
2002
|
+
const belowMidpoint=!!row.dataset.rowId&&event.clientY>bounds.top+bounds.height/2;
|
|
2003
|
+
showRowDrop(!belowMidpoint?target:target+1<grid.display.length?target+1:null);
|
|
2004
|
+
});
|
|
2005
|
+
function finishRowDrag(event){
|
|
2006
|
+
if(rowDrag?.pointerId!==event.pointerId)return;
|
|
2007
|
+
const {target,ids:sources}=rowDrag;
|
|
2008
|
+
showRowDrop(null);
|
|
2009
|
+
for(const row of tableBody.querySelectorAll(".row-drag-source"))row.classList.remove("row-drag-source");
|
|
2010
|
+
rowDragPreview.hidden=true;
|
|
2011
|
+
rowDrag=null;
|
|
2012
|
+
const targetId=target===null?undefined:grid.display[target]?.id;
|
|
2013
|
+
if(event.type!=="pointerup"||targetId===undefined||!canDragRows()||state.editingCell)return;
|
|
2014
|
+
const ids=trace?.rowOrderIds()??state.currentRows.map(rowId);
|
|
2015
|
+
const source=ids.indexOf(sources[0]);
|
|
2016
|
+
const insertion=targetId===""?ids.length:ids.indexOf(targetId);
|
|
2017
|
+
const count=sources.length;
|
|
2018
|
+
if(insertion>=source&&insertion<=source+count)return;
|
|
2019
|
+
reorderRequirement(source,insertion-(source<insertion?count:0),count);
|
|
2020
|
+
}
|
|
2021
|
+
for(const event of ["pointerup","pointercancel","lostpointercapture"]){
|
|
2022
|
+
tableBody.addEventListener(event,finishRowDrag);
|
|
2023
|
+
}
|
|
2024
|
+
tableBody.addEventListener("click",event=>{
|
|
2025
|
+
if(event.target.closest("[data-add-entry]")&&!state.editingCell)addRequirement("end");
|
|
2026
|
+
if(!state.editingCell&&!event.target.closest("button,a,form,.row-grip")){
|
|
2027
|
+
const cell=event.target.closest("[data-grid-cell]");
|
|
2028
|
+
if(!cell)return;
|
|
2029
|
+
if(event.shiftKey){
|
|
2030
|
+
event.stopPropagation();
|
|
2031
|
+
extendSelection(cellPosition(cell));
|
|
2032
|
+
return;
|
|
2033
|
+
}
|
|
2034
|
+
const position=cellPosition(cell);
|
|
2035
|
+
rangeSelection=cell.dataset.column===data.meta.idColumn&&cell.parentElement.dataset.rowId
|
|
2036
|
+
?{anchor:position,extent:position,wholeRows:true}:null;
|
|
2037
|
+
}
|
|
2038
|
+
if(vimKeys()||!state.editingCell||event.target.closest("button,a,form"))return;
|
|
2039
|
+
const cell=event.target.closest("[data-grid-cell]");
|
|
2040
|
+
const editor=tableBody.querySelector("[data-cell-editor]");
|
|
2041
|
+
if(cell&&editor&&cell!==editor.closest("[data-grid-cell]")){
|
|
2042
|
+
event.stopPropagation();
|
|
2043
|
+
applyCellEdit(editor,cellPosition(cell));
|
|
2044
|
+
}
|
|
2045
|
+
});
|
|
2046
|
+
for(const position of ["above","below","end"])$("#add-"+position).addEventListener("click",()=>addRequirement(position));$("#move-up").addEventListener("click",()=>moveRequirement(-1));$("#move-down").addEventListener("click",()=>moveRequirement(1));$("#rename-requirement").addEventListener("click",renameRequirement);$("#delete-requirement").addEventListener("click",deleteSelectedRecord);$("#undo-edit").addEventListener("click",undoEdit);$("#redo-edit").addEventListener("click",redoEdit);$("#compare-menu").addEventListener("click",event=>{const button=event.target.closest("[data-compare]");if(!button)return;setCompareWith(button.dataset.compare==="none"?null:button.dataset.compare);render();});$("#save-csv").addEventListener("click",()=>saveCsv());$("#save-as").addEventListener("click",()=>saveCsv(true));$("#save-copy").addEventListener("click",()=>saveReportCopy());$("#export-review").addEventListener("click",()=>saveReportCopy({forReview:true}));$("#export-review-changes").addEventListener("click",()=>saveReportCopy({forReview:true,withChanges:true}));
|
|
2047
|
+
document.addEventListener("click",event=>{const cell=event.target.closest("[data-bool-toggle]")?.closest("[data-grid-cell]");if(cell)toggleBooleanCell(cell);});
|
|
2048
|
+
document.addEventListener("submit",event=>{const form=event.target.closest("[data-cell-editor]");if(form){event.preventDefault();event.stopImmediatePropagation();applyCellEdit(form);}},true);document.addEventListener("dblclick",event=>{
|
|
2049
|
+
const cell=event.target.closest("[data-grid-cell]");
|
|
2050
|
+
if(cell&&developMode()&&!event.target.closest("form,button,a,[data-bool-toggle]")){
|
|
2051
|
+
if(startCellEdit(cell,{selection:"auto"}))event.preventDefault();
|
|
2052
|
+
}
|
|
2053
|
+
},true);document.addEventListener("click",event=>{if(event.detail===3&&event.target.matches("[data-cell-editor] textarea")){event.preventDefault();event.target.select();}if(event.target.closest("[data-cancel-cell-edit]")){event.preventDefault();event.stopImmediatePropagation();cancelCellEdit();}},true);document.addEventListener("keydown",event=>{const editor=event.target.closest("[data-cell-editor]");if(editor){
|
|
2054
|
+
event.stopImmediatePropagation();
|
|
2055
|
+
if(event.isComposing)return;
|
|
2056
|
+
const suggestions=editor.querySelector(".cell-suggestions");
|
|
2057
|
+
const suggestion=event.target.closest(".cell-suggestions button");
|
|
2058
|
+
if(!event.altKey&&!event.ctrlKey&&!event.metaKey&&!event.shiftKey){
|
|
2059
|
+
let next;
|
|
2060
|
+
if(event.key==="ArrowDown"&&!suggestions.hidden){
|
|
2061
|
+
next=suggestion?suggestion.nextElementSibling:event.target.matches("textarea")?suggestions.firstElementChild:null;
|
|
2062
|
+
}else if(event.key==="ArrowUp"&&suggestion){
|
|
2063
|
+
next=suggestion.previousElementSibling||editor.querySelector("textarea");
|
|
2064
|
+
}
|
|
2065
|
+
if(next){
|
|
2066
|
+
event.preventDefault();
|
|
2067
|
+
next.focus();
|
|
2068
|
+
return;
|
|
2069
|
+
}
|
|
2070
|
+
}
|
|
2071
|
+
if((event.target.matches("textarea")||suggestion)&&event.key==="Tab"&&!event.ctrlKey&&!event.metaKey&&!event.altKey){
|
|
2072
|
+
event.preventDefault();
|
|
2073
|
+
applyCellEdit(editor,tabNeighbor(cellPosition(editor.closest("[data-grid-cell]")),event.shiftKey));
|
|
2074
|
+
return;
|
|
2075
|
+
}
|
|
2076
|
+
if(!vimKeys()&&event.target.matches("textarea")&&event.key==="Enter"&&!event.ctrlKey&&!event.metaKey){
|
|
2077
|
+
event.preventDefault();
|
|
2078
|
+
if(event.altKey){
|
|
2079
|
+
const textarea=event.target;
|
|
2080
|
+
textarea.setRangeText("\n",textarea.selectionStart,textarea.selectionEnd,"end");
|
|
2081
|
+
textarea.dispatchEvent(new Event("input",{bubbles:true}));
|
|
2082
|
+
}else{
|
|
2083
|
+
const position=cellPosition(editor.closest("[data-grid-cell]")),row=position.row+(event.shiftKey?-1:1);
|
|
2084
|
+
const next=row>=0&&row<grid.display.length?{row,column:position.column}:null;
|
|
2085
|
+
applyCellEdit(editor,next,!event.shiftKey&&!next);
|
|
2086
|
+
}
|
|
2087
|
+
return;
|
|
2088
|
+
}
|
|
2089
|
+
if(event.key==="Escape"){event.preventDefault();event.stopImmediatePropagation();cancelCellEdit();}else if(event.key==="Enter"&&(event.ctrlKey||event.metaKey)){event.preventDefault();event.stopImmediatePropagation();applyCellEdit(editor);}return;}if(state.editingCell&&event.key==="Escape"){event.preventDefault();event.stopImmediatePropagation();cancelCellEdit();return;}if(developMode()&&(event.ctrlKey||event.metaKey)&&event.key.toLocaleLowerCase()==="z"&&!event.target.matches("input,textarea,select")){event.preventDefault();event.stopImmediatePropagation();event.shiftKey?redoEdit():undoEdit();if(event.target.matches("[data-grid-cell]"))focusGridCell(state.focus.row,state.focus.column);return;}if(developMode()&&(event.ctrlKey||event.metaKey)&&event.key.toLocaleLowerCase()==="y"&&!event.target.matches("input,textarea,select")){event.preventDefault();event.stopImmediatePropagation();redoEdit();if(event.target.matches("[data-grid-cell]"))focusGridCell(state.focus.row,state.focus.column);return;}const cell=event.target.closest("[data-grid-cell]");if(developMode()&&cell&&!event.target.closest("button,a")&&(event.key==="Enter"||event.key==="F2")){event.preventDefault();event.stopImmediatePropagation();
|
|
2090
|
+
const addButton=event.key==="Enter"&&cell.querySelector("[data-add-entry]");
|
|
2091
|
+
if(addButton){
|
|
2092
|
+
if(!event.repeat)addButton.click();
|
|
2093
|
+
}else startCellEdit(cell,{selection:event.key==="F2"?"auto":"all"});
|
|
2094
|
+
}},true);
|
|
2095
|
+
function matches(row){if(trace?.revealed(row.id))return true;if(trace&&!trace.matches(row))return false;if(quality.only&&!quality.findings.has(row.id))return false;if(state.compareWith==="old"&&!data.options.includeUnchanged&&row.status==="unchanged"&&row.id!==quality.revealId)return false;if(state.compareWith!==null&&!state.statuses.has(row.status))return false;if(state.commentsOnly&&!state.comments.some(c=>c.requirementId===row.id))return false;if(state.idFilter&&!state.idFilter.ids.has(row.id))return false;for(const[column,query]of state.filters){if(query&&!row.cells[column].search.includes(query.toLocaleLowerCase()))return false;}for(const[column,values]of state.valueFilters){if(values.size&&!valueFilterMatches(values,valueFor(row,column)))return false;}return true;}function ensureCellVisible(cell){if(cellDrag?.moved)return;const wrap=$(".table-wrap"),wr=wrap.getBoundingClientRect(),cr=cell.getBoundingClientRect(),statusWidth=diffActive()?118:0,safeLeft=wr.left+statusWidth+2,safeTop=wr.top+68,safeBottom=wr.top+wrap.clientHeight-2,panelLeft=Math.min(review.hidden?Infinity:review.getBoundingClientRect().left,trace&&!trace.panel.hidden?trace.panel.getBoundingClientRect().left:Infinity),safeRight=Math.min(wr.left+wrap.clientWidth-2,panelLeft-2);if(cr.left<safeLeft)wrap.scrollLeft+=cr.left-safeLeft;else if(cr.right>safeRight)wrap.scrollLeft+=cr.right-safeRight;if(cr.top<safeTop)wrap.scrollTop+=cr.top-safeTop;else if(cr.bottom>safeBottom)wrap.scrollTop+=cr.bottom-safeBottom;}
|
|
2096
|
+
function syncReviewerLabel(){
|
|
2097
|
+
const initials=reviewerInitials();
|
|
2098
|
+
$("#reviewer-label").textContent=initials||"Set initials";
|
|
2099
|
+
$("#reviewer-details summary").setAttribute("aria-label",initials
|
|
2100
|
+
?`Reviewer initials: ${initials}`:"Set reviewer initials");
|
|
2101
|
+
}
|
|
2102
|
+
function focusReviewerInitials(){
|
|
2103
|
+
$("#reviewer-details").open=true;
|
|
2104
|
+
$("#reviewer-initials").focus();
|
|
2105
|
+
}
|
|
2106
|
+
const reviewerDetails=$("#reviewer-details");
|
|
2107
|
+
reviewerDetails.addEventListener("toggle",()=>{
|
|
2108
|
+
if(reviewerDetails.open)focusReviewerInitials();
|
|
2109
|
+
});
|
|
2110
|
+
document.addEventListener("click",event=>{
|
|
2111
|
+
for(const disclosure of document.querySelectorAll(".header-disclosure[open]")){
|
|
2112
|
+
if(!event.composedPath().includes(disclosure))disclosure.open=false;
|
|
2113
|
+
}
|
|
2114
|
+
});
|
|
2115
|
+
document.addEventListener("keydown",event=>{
|
|
2116
|
+
const disclosure=event.target.closest(".header-disclosure[open]");
|
|
2117
|
+
if(!disclosure||event.key!=="Escape")return;
|
|
2118
|
+
event.preventDefault();
|
|
2119
|
+
disclosure.open=false;
|
|
2120
|
+
disclosure.querySelector("summary").focus();
|
|
2121
|
+
},true);
|
|
2122
|
+
const menus=[...document.querySelectorAll(".toolbar details.popup-menu")];
|
|
2123
|
+
for(const menu of menus){
|
|
2124
|
+
const summary=menu.querySelector("summary");
|
|
2125
|
+
summary.addEventListener("pointerenter",event=>{
|
|
2126
|
+
if(event.pointerType!=="mouse"||menu.open||menu.hidden)return;
|
|
2127
|
+
const openMenu=menus.find(item=>item.open);
|
|
2128
|
+
if(!openMenu)return;
|
|
2129
|
+
const hadFocus=openMenu.contains(document.activeElement);
|
|
2130
|
+
closeHeaderPopups(menu);
|
|
2131
|
+
menu.open=true;
|
|
2132
|
+
if(hadFocus)summary.focus({preventScroll:true});
|
|
2133
|
+
});
|
|
2134
|
+
}
|
|
2135
|
+
document.addEventListener("focusin",event=>{
|
|
2136
|
+
closeHeaderPopups(event.target.closest(".toolbar .popup-menu"));
|
|
2137
|
+
});
|
|
2138
|
+
const settings=$("#settings-dialog"),commandSearch=$("#command-search");
|
|
2139
|
+
const commandQuery=$("#command-query"),commandResults=$("#command-results");
|
|
2140
|
+
$("#open-settings").addEventListener("click",()=>{
|
|
2141
|
+
closeHeaderPopups();
|
|
2142
|
+
settings.showModal();
|
|
2143
|
+
keyboardMode.focus();
|
|
2144
|
+
});
|
|
2145
|
+
$("#close-settings").addEventListener("click",()=>settings.close());
|
|
2146
|
+
settings.addEventListener("close",()=>restoreSelectedCell());
|
|
2147
|
+
function renderCommandResults(){
|
|
2148
|
+
const terms=commandQuery.value.toLocaleLowerCase().trim().split(/\s+/);
|
|
2149
|
+
commandResults.replaceChildren();
|
|
2150
|
+
for(const menu of menus){
|
|
2151
|
+
if(menu.id==="active-filters")continue;
|
|
2152
|
+
const group=menu.querySelector("summary").textContent;
|
|
2153
|
+
for(const item of menu.querySelectorAll(".popover button,.popover input[type=checkbox]")){
|
|
2154
|
+
if(item.id==="search-menus"||item.disabled||item.closest("[hidden]"))continue;
|
|
2155
|
+
const hint=item.querySelector("kbd:not([hidden])");
|
|
2156
|
+
const labelNode=item.labels?.[0]??item;
|
|
2157
|
+
const label=[...labelNode.childNodes].filter(node=>!node.matches?.("kbd"))
|
|
2158
|
+
.map(node=>node.textContent).join("").trim();
|
|
2159
|
+
if(!terms.every(term=>`${group} ${label} ${item.getAttribute("aria-label")??""}`.toLocaleLowerCase().includes(term)))continue;
|
|
2160
|
+
const result=document.createElement("button");
|
|
2161
|
+
const name=document.createElement("span");
|
|
2162
|
+
const context=document.createElement("small");
|
|
2163
|
+
context.textContent=group;
|
|
2164
|
+
name.append(context,document.createElement("br"),label);
|
|
2165
|
+
result.append(name);
|
|
2166
|
+
if(hint)result.append(hint.cloneNode(true));
|
|
2167
|
+
result.addEventListener("click",()=>{
|
|
2168
|
+
commandSearch.close();
|
|
2169
|
+
item.click();
|
|
2170
|
+
});
|
|
2171
|
+
commandResults.append(result);
|
|
2172
|
+
}
|
|
2173
|
+
}
|
|
2174
|
+
$("#command-empty").hidden=commandResults.childElementCount>0;
|
|
2175
|
+
}
|
|
2176
|
+
function openCommandSearch(){
|
|
2177
|
+
if(document.querySelector("dialog[open]"))return;
|
|
2178
|
+
closeHeaderPopups();
|
|
2179
|
+
commandQuery.value="";
|
|
2180
|
+
renderCommandResults();
|
|
2181
|
+
commandSearch.showModal();
|
|
2182
|
+
commandQuery.focus();
|
|
2183
|
+
}
|
|
2184
|
+
$("#search-menus").addEventListener("click",event=>{
|
|
2185
|
+
event.currentTarget.closest(".popup-menu").querySelector("summary").focus();
|
|
2186
|
+
openCommandSearch();
|
|
2187
|
+
});
|
|
2188
|
+
$("#close-command-search").addEventListener("click",()=>commandSearch.close());
|
|
2189
|
+
commandQuery.addEventListener("input",renderCommandResults);
|
|
2190
|
+
commandSearch.addEventListener("keydown",event=>{
|
|
2191
|
+
if(event.isComposing)return;
|
|
2192
|
+
const active=event.target,results=[...commandResults.children];
|
|
2193
|
+
if(event.key==="ArrowDown"||event.key==="ArrowUp"){
|
|
2194
|
+
const index=results.indexOf(active);
|
|
2195
|
+
const next=event.key==="ArrowDown"?results[index+1]:results[index-1]||commandQuery;
|
|
2196
|
+
next?.focus();
|
|
2197
|
+
}else if(event.key==="Enter"&&active===commandQuery){
|
|
2198
|
+
results[0]?.click();
|
|
2199
|
+
}else return;
|
|
2200
|
+
event.preventDefault();
|
|
2201
|
+
});
|
|
2202
|
+
for(const dialog of [settings,commandSearch]){
|
|
2203
|
+
dialog.addEventListener("keydown",event=>{
|
|
2204
|
+
if(event.key==="Escape")event.stopPropagation();
|
|
2205
|
+
});
|
|
2206
|
+
}
|
|
2207
|
+
document.addEventListener("keydown",event=>{
|
|
2208
|
+
if(event.altKey&&!event.ctrlKey&&!event.metaKey&&!event.shiftKey&&!event.isComposing
|
|
2209
|
+
&&(event.code==="Slash"||event.key==="/")){
|
|
2210
|
+
event.preventDefault();
|
|
2211
|
+
openCommandSearch();
|
|
2212
|
+
}
|
|
2213
|
+
});
|
|
2214
|
+
function menuItems(menu){
|
|
2215
|
+
return [...menu.querySelectorAll("button,input")].filter(item=>!item.disabled&&item.getClientRects().length);
|
|
2216
|
+
}
|
|
2217
|
+
document.addEventListener("click",event=>{
|
|
2218
|
+
const menu=event.composedPath().find(node=>node instanceof Element&&node.matches(".toolbar details.popup-menu"));
|
|
2219
|
+
if(!menu){closeHeaderPopups();return;}
|
|
2220
|
+
const summary=menu.querySelector("summary");
|
|
2221
|
+
if(event.target.closest("summary"))closeHeaderPopups(menu);
|
|
2222
|
+
else if(event.target.closest("button")){
|
|
2223
|
+
menu.open=false;
|
|
2224
|
+
if(menu.contains(document.activeElement)||document.activeElement===document.body)summary.focus();
|
|
2225
|
+
}
|
|
2226
|
+
});
|
|
2227
|
+
document.addEventListener("keydown",event=>{
|
|
2228
|
+
const menu=event.target.closest(".toolbar details.popup-menu");
|
|
2229
|
+
if(!menu||event.altKey||event.ctrlKey||event.metaKey||event.isComposing)return;
|
|
2230
|
+
const summary=menu.querySelector("summary");
|
|
2231
|
+
if(event.key==="Escape"&&menu.open){
|
|
2232
|
+
menu.open=false;
|
|
2233
|
+
summary.focus();
|
|
2234
|
+
}else if(event.target===summary&&["Enter"," "].includes(event.key)){
|
|
2235
|
+
if(menu.id==="active-filters")return;
|
|
2236
|
+
closeHeaderPopups(menu);
|
|
2237
|
+
menu.open=true;
|
|
2238
|
+
menuItems(menu)[0]?.focus();
|
|
2239
|
+
}else if(event.key==="Enter"&&event.target.matches('input[type="checkbox"]')){
|
|
2240
|
+
event.target.click();
|
|
2241
|
+
}else if(["ArrowLeft","ArrowRight"].includes(event.key)){
|
|
2242
|
+
const visible=menus.filter(item=>!item.hidden),offset=event.key==="ArrowRight"?1:-1;
|
|
2243
|
+
const next=visible[(visible.indexOf(menu)+offset+visible.length)%visible.length];
|
|
2244
|
+
const wasOpen=menu.open;
|
|
2245
|
+
closeHeaderPopups();
|
|
2246
|
+
next.open=wasOpen;
|
|
2247
|
+
const target=wasOpen&&event.target!==summary?menuItems(next)[0]:null;
|
|
2248
|
+
(target||next.querySelector("summary")).focus();
|
|
2249
|
+
}else if(["ArrowDown","ArrowUp","Home","End"].includes(event.key)){
|
|
2250
|
+
closeHeaderPopups(menu);
|
|
2251
|
+
menu.open=true;
|
|
2252
|
+
const items=menuItems(menu),index=items.indexOf(event.target);
|
|
2253
|
+
const target=event.key==="Home"?0:event.key==="End"?items.length-1:event.key==="ArrowDown"?(index+1)%items.length:(index<=0?items.length-1:index-1);
|
|
2254
|
+
items[target]?.focus();
|
|
2255
|
+
}else return;
|
|
2256
|
+
event.preventDefault();
|
|
2257
|
+
event.stopImmediatePropagation();
|
|
2258
|
+
},true);
|
|
2259
|
+
"""
|
|
2260
|
+
+ QUALITY_JS
|
|
2261
|
+
)
|
|
2262
|
+
|
|
2263
|
+
FILTER_JS = r"""
|
|
2264
|
+
const naturalCompare=new Intl.Collator(undefined,{numeric:true,sensitivity:"base"}).compare;
|
|
2265
|
+
// Listed options are never blank, so "" cannot collide with a real value.
|
|
2266
|
+
const EMPTY_FILTER="";
|
|
2267
|
+
function isBlankValue(value){return String(value??"").trim()==="";}
|
|
2268
|
+
function valueFilterMatches(selected,value){return selected.has(value)||(selected.has(EMPTY_FILTER)&&isBlankValue(value));}
|
|
2269
|
+
function filteredToEmpty(activeFilters,shown,total){return activeFilters>0&&shown===0&&total>0;}
|
|
2270
|
+
function valueFilterLabel(value){return value===EMPTY_FILTER?"Empty":`“${value}”`;}
|
|
2271
|
+
function valueFilterOptions(values){
|
|
2272
|
+
const blank=values.some(isBlankValue);
|
|
2273
|
+
const listed=[...new Set(values.filter(value=>!isBlankValue(value)))]
|
|
2274
|
+
.sort(naturalCompare);
|
|
2275
|
+
return {blank,listed};
|
|
2276
|
+
}
|
|
2277
|
+
"""
|
|
2278
|
+
|
|
2279
|
+
POPOVER_JS = r"""
|
|
2280
|
+
let activePopover=null;
|
|
2281
|
+
function popoverPlacement(anchor,size,viewport,margin=8,gap=5){
|
|
2282
|
+
const below=viewport.height-margin-gap-anchor.bottom,above=anchor.top-gap-margin;
|
|
2283
|
+
const under=size.height<=below||(size.height>above&&below>=above);
|
|
2284
|
+
const height=Math.min(size.height,Math.max(under?below:above,Math.min(120,viewport.height-2*margin)));
|
|
2285
|
+
const top=under?anchor.bottom+gap:anchor.top-gap-height;
|
|
2286
|
+
return {
|
|
2287
|
+
left:Math.max(margin,Math.min(anchor.left,viewport.width-size.width-margin)),
|
|
2288
|
+
top:Math.max(margin,Math.min(top,viewport.height-height-margin)),
|
|
2289
|
+
maxHeight:height<size.height?height:null
|
|
2290
|
+
};
|
|
2291
|
+
}
|
|
2292
|
+
function positionPopover(element,anchor){
|
|
2293
|
+
element.hidden=false;
|
|
2294
|
+
element.style.maxHeight="";
|
|
2295
|
+
const {left,top,maxHeight}=popoverPlacement(anchor.getBoundingClientRect(),
|
|
2296
|
+
{width:element.offsetWidth,height:element.offsetHeight},{width:innerWidth,height:innerHeight});
|
|
2297
|
+
element.style.left=`${left}px`;
|
|
2298
|
+
element.style.top=`${top}px`;
|
|
2299
|
+
if(maxHeight!==null)element.style.maxHeight=`${maxHeight}px`;
|
|
2300
|
+
}
|
|
2301
|
+
function anchoredPopover(popup){
|
|
2302
|
+
let anchor=null;
|
|
2303
|
+
const popover={
|
|
2304
|
+
close(restoreFocus=false){
|
|
2305
|
+
if(!anchor)return;
|
|
2306
|
+
const previous=anchor,focused=popup.contains(document.activeElement);
|
|
2307
|
+
anchor=null;
|
|
2308
|
+
if(activePopover===popover)activePopover=null;
|
|
2309
|
+
popup.hidden=true;
|
|
2310
|
+
previous.setAttribute("aria-expanded","false");
|
|
2311
|
+
if(!restoreFocus&&!focused)return;
|
|
2312
|
+
if(previous.isConnected)previous.focus({preventScroll:true});
|
|
2313
|
+
else restoreSelectedCell();
|
|
2314
|
+
},
|
|
2315
|
+
open(button,fill){
|
|
2316
|
+
if(anchor===button){popover.close(true);return;}
|
|
2317
|
+
activePopover?.close();
|
|
2318
|
+
const focus=fill();
|
|
2319
|
+
anchor=button;
|
|
2320
|
+
activePopover=popover;
|
|
2321
|
+
button.setAttribute("aria-expanded","true");
|
|
2322
|
+
positionPopover(popup,button);
|
|
2323
|
+
focus.focus({preventScroll:true});
|
|
2324
|
+
}
|
|
2325
|
+
};
|
|
2326
|
+
document.addEventListener("click",event=>{
|
|
2327
|
+
if(!anchor||popup.contains(event.target)||anchor.contains(event.target))return;
|
|
2328
|
+
popover.close(!document.activeElement||document.activeElement===document.body);
|
|
2329
|
+
});
|
|
2330
|
+
document.addEventListener("keydown",event=>{
|
|
2331
|
+
if(event.key!=="Escape"||!anchor)return;
|
|
2332
|
+
event.preventDefault();
|
|
2333
|
+
event.stopImmediatePropagation();
|
|
2334
|
+
popover.close(true);
|
|
2335
|
+
},true);
|
|
2336
|
+
document.addEventListener("scroll",event=>{
|
|
2337
|
+
if(anchor&&!popup.contains(event.target))popover.close();
|
|
2338
|
+
},true);
|
|
2339
|
+
window.addEventListener("resize",()=>popover.close());
|
|
2340
|
+
return popover;
|
|
2341
|
+
}
|
|
2342
|
+
function findingMarker(className,symbol,label,open){
|
|
2343
|
+
const marker=document.createElement("button");
|
|
2344
|
+
marker.type="button";
|
|
2345
|
+
marker.className=className;
|
|
2346
|
+
marker.textContent=symbol;
|
|
2347
|
+
marker.title=label;
|
|
2348
|
+
marker.setAttribute("aria-label",label);
|
|
2349
|
+
marker.setAttribute("aria-haspopup","dialog");
|
|
2350
|
+
marker.setAttribute("aria-controls","finding-popover");
|
|
2351
|
+
marker.setAttribute("aria-expanded","false");
|
|
2352
|
+
marker.addEventListener("click",()=>open(marker));
|
|
2353
|
+
return marker;
|
|
2354
|
+
}
|
|
2355
|
+
function createFindingPopover(){
|
|
2356
|
+
const popup=$("#finding-popover"),title=$("#finding-popover-title");
|
|
2357
|
+
const list=$("#finding-popover-list"),footer=$("#finding-popover-actions");
|
|
2358
|
+
const popover=anchoredPopover(popup);
|
|
2359
|
+
$("#finding-popover-close").addEventListener("click",()=>popover.close(true));
|
|
2360
|
+
const buttons=actions=>actions.map(({label,run})=>{
|
|
2361
|
+
const button=document.createElement("button");
|
|
2362
|
+
button.type="button";
|
|
2363
|
+
button.textContent=label;
|
|
2364
|
+
button.addEventListener("click",()=>{popover.close();run();});
|
|
2365
|
+
return button;
|
|
2366
|
+
});
|
|
2367
|
+
return {close:popover.close,open(marker,{heading,findings,actions}){
|
|
2368
|
+
popover.open(marker,()=>{
|
|
2369
|
+
title.textContent=heading;
|
|
2370
|
+
list.replaceChildren(...findings.map(finding=>{
|
|
2371
|
+
const item=document.createElement("li");
|
|
2372
|
+
if(finding.name){
|
|
2373
|
+
const name=document.createElement("strong");
|
|
2374
|
+
name.textContent=finding.name;
|
|
2375
|
+
item.append(name,document.createElement("br"));
|
|
2376
|
+
}
|
|
2377
|
+
item.append(finding.detail);
|
|
2378
|
+
if(finding.actions){
|
|
2379
|
+
const row=document.createElement("div");
|
|
2380
|
+
row.className="comment-actions";
|
|
2381
|
+
row.append(...buttons(finding.actions));
|
|
2382
|
+
item.append(row);
|
|
2383
|
+
}
|
|
2384
|
+
return item;
|
|
2385
|
+
}));
|
|
2386
|
+
footer.replaceChildren(...buttons(actions));
|
|
2387
|
+
return title;
|
|
2388
|
+
});
|
|
2389
|
+
}};
|
|
2390
|
+
}
|
|
2391
|
+
"""
|
|
2392
|
+
|
|
2393
|
+
WINDOW_JS = r"""
|
|
2394
|
+
const WINDOW_THRESHOLD=300,WINDOW_OVERSCAN=15,ROW_HEIGHT_GUESS=60,GRID_HEAD_ROWS=2;
|
|
2395
|
+
function ariaRowIndex(index,leadingRows=0){return GRID_HEAD_ROWS+leadingRows+index+1;}
|
|
2396
|
+
function rowOffsets(ids,heights,guess=ROW_HEIGHT_GUESS){
|
|
2397
|
+
let sum=0;
|
|
2398
|
+
for(const height of heights.values())sum+=height;
|
|
2399
|
+
const fallback=heights.size?sum/heights.size:guess,offsets=new Float64Array(ids.length+1);
|
|
2400
|
+
ids.forEach((id,i)=>{offsets[i+1]=offsets[i]+(heights.get(id)??fallback);});
|
|
2401
|
+
return offsets;
|
|
2402
|
+
}
|
|
2403
|
+
function windowRange(offsets,top,height,overscan=WINDOW_OVERSCAN,threshold=WINDOW_THRESHOLD){
|
|
2404
|
+
const count=offsets.length-1;
|
|
2405
|
+
if(count<=threshold||count<=0)return {start:0,end:Math.max(0,count),top:0,bottom:0};
|
|
2406
|
+
const rowAt=y=>{
|
|
2407
|
+
let low=0,high=count-1;
|
|
2408
|
+
while(low<high){const mid=(low+high+1)>>1;if(offsets[mid]<=y)low=mid;else high=mid-1;}
|
|
2409
|
+
return low;
|
|
2410
|
+
};
|
|
2411
|
+
const start=Math.max(0,rowAt(Math.max(0,top))-overscan),end=Math.min(count,rowAt(Math.max(0,top+height))+1+overscan);
|
|
2412
|
+
return {start,end,top:offsets[start],bottom:offsets[count]-offsets[end]};
|
|
2413
|
+
}
|
|
2414
|
+
function edgeScrollSpeed(y,top,bottom,zone=40,max=28){
|
|
2415
|
+
const toward=y<top+zone?(y-top-zone)/zone:y>bottom-zone?(y-bottom+zone)/zone:0;
|
|
2416
|
+
return Math.max(-1,Math.min(1,toward))*max;
|
|
2417
|
+
}
|
|
2418
|
+
"""
|
|
2419
|
+
|
|
2420
|
+
INITIAL_RENDER_JS = """
|
|
2421
|
+
updateDirty();
|
|
2422
|
+
render();
|
|
2423
|
+
draftsStart();
|
|
2424
|
+
"""
|
|
2425
|
+
|
|
2426
|
+
|
|
2427
|
+
TEMPLATE = r"""<!doctype html>
|
|
2428
|
+
<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><meta http-equiv="Content-Security-Policy" content="default-src 'none'; style-src 'unsafe-inline'; script-src 'unsafe-inline'; img-src data:; form-action 'none'"><title>__TITLE__</title><style>__CSS__</style></head>
|
|
2429
|
+
<body><main class="page">
|
|
2430
|
+
<header class="report-header">
|
|
2431
|
+
<div class="report-identity">
|
|
2432
|
+
<h1 title="__TITLE__">__TITLE__</h1>
|
|
2433
|
+
<details class="header-disclosure report-info">
|
|
2434
|
+
<summary aria-label="Report information" title="__META__">i</summary>
|
|
2435
|
+
<div class="popover"><div id="metadata">__META__</div><div class="summary">__SUMMARY__</div></div>
|
|
2436
|
+
</details>
|
|
2437
|
+
<span id="document-mode" class="badge mode-badge __DOCUMENT_MODE__">__DOCUMENT_MODE_LABEL__</span>
|
|
2438
|
+
</div>
|
|
2439
|
+
<div class="save-area">
|
|
2440
|
+
<details id="dirty-indicator" class="header-disclosure dirty" hidden>
|
|
2441
|
+
<summary>Unsaved changes</summary>
|
|
2442
|
+
<div id="dirty-details" class="popover"></div>
|
|
2443
|
+
</details>
|
|
2444
|
+
<details id="reviewer-details" class="header-disclosure comments-only">
|
|
2445
|
+
<summary aria-label="Reviewer initials"><span id="reviewer-label">Set initials</span> ▾</summary>
|
|
2446
|
+
<div class="popover"><label for="reviewer-initials">Reviewer initials</label>
|
|
2447
|
+
<input id="reviewer-initials" maxlength="16" value="__INITIALS__"></div>
|
|
2448
|
+
</details>
|
|
2449
|
+
</div>
|
|
2450
|
+
<div id="save-status" class="meta" role="status"></div>
|
|
2451
|
+
<div id="dirty-announcement" class="sr-only" role="status"></div>
|
|
2452
|
+
<div class="print-details meta">__META__<div class="summary">__SUMMARY__</div></div>
|
|
2453
|
+
</header>
|
|
2454
|
+
__DRAFTS_HTML__
|
|
2455
|
+
__PACKAGE_HTML__
|
|
2456
|
+
<section class="toolbar" aria-label="Table controls">
|
|
2457
|
+
<details class="popup-menu"><summary>File</summary><div class="popover"><button id="save-csv" class="develop-only">Save CSV</button><button id="save-as" class="develop-only">Save CSV as…</button><button id="save-copy">Save report copy</button><button id="export-review" class="develop-only">Export for review</button><button id="export-review-changes" class="develop-only">Export changes for review</button><label class="develop-only"><input id="autosave" type="checkbox" checked> Autosave</label></div></details>
|
|
2458
|
+
<details id="edit-menu" class="popup-menu develop-only"><summary>Edit</summary><div class="popover"><button id="undo-edit" disabled>Undo <kbd data-shortcut="Mod Z"></kbd></button><button id="redo-edit" disabled>Redo <kbd data-shortcut="Mod Shift Z"></kbd></button><div class="menu-section"><button id="copy-cells" disabled>Copy <kbd data-shortcut="Mod C"></kbd></button><button id="paste-cells" disabled>Paste <kbd data-shortcut="Mod V"></kbd></button><button id="clear-cells" disabled>Clear cells <kbd data-shortcut="Delete" data-vim-shortcut=""></kbd></button></div><div class="menu-section"><button id="add-end">Add requirement…</button><button id="add-above">Add above… <kbd data-shortcut="Mod Shift ↑" data-vim-shortcut="O"></kbd></button><button id="add-below">Add below… <kbd data-shortcut="Mod Shift ↓" data-vim-shortcut="o"></kbd></button><button id="move-up">Move up <kbd data-shortcut="Alt Shift ↑" data-vim-shortcut=""></kbd></button><button id="move-down">Move down <kbd data-shortcut="Alt Shift ↓" data-vim-shortcut=""></kbd></button><button id="rename-requirement">Rename ID…</button><button id="delete-requirement"><span id="delete-record-label">Delete requirement</span> <kbd data-shortcut="Mod Backspace" data-vim-shortcut=""></kbd></button></div><div class="menu-section diff-only"><button id="revert-selected-cell" disabled>Revert selected cell</button><button id="restore-deleted-requirement" disabled>Restore deleted requirement</button></div></div></details>
|
|
2459
|
+
<details class="popup-menu"><summary>View</summary><div class="popover"><div id="compare-menu" class="compare-group" role="group" aria-labelledby="compare-label" hidden><div id="compare-label" class="menu-label">Compare with</div><button id="compare-nothing" data-compare="none">Nothing</button><button id="unsaved-diff" class="develop-only" data-compare="saved">Last save</button><button id="compare-old" data-compare="old" hidden></button><div id="compare-baselines"></div></div><button id="review-comparison" hidden>Show current requirements</button><button id="view-toggle" class="diff-only">Diff view</button><button id="reset-view">Reset view</button><button id="browse-comments" class="comments-only" aria-expanded="false" aria-controls="review-panel">Browse comments</button>__TRACE_MENU__<button id="check-quality" class="develop-only">Check requirement quality</button><button id="open-settings" class="develop-only">Settings…</button></div></details>
|
|
2460
|
+
<details id="filter-menu" class="popup-menu"><summary>Filter</summary><div class="popover"><button id="comments-only-rows" class="comments-only" aria-pressed="false">Comments only</button><button id="clear-filters">Clear filters</button><div class="diff-only menu-section"><button id="changes-only">Changes only</button><label><input type="checkbox" data-status="added"> Added</label><label><input type="checkbox" data-status="removed"> Removed</label><label><input type="checkbox" data-status="changed"> Changed</label><label><input type="checkbox" data-status="unchanged"> Unchanged</label></div></div></details>
|
|
2461
|
+
<details id="columns-menu" class="popup-menu"><summary>Columns</summary><div class="popover"><div id="column-list"></div><div class="menu-section"><button id="show-all-columns">Show all</button><button id="default-columns">Show defaults</button></div><div id="hidden-filter-warning" class="meta"></div></div></details>
|
|
2462
|
+
<details class="popup-menu"><summary>Help</summary><div class="popover"><button id="show-help">Keyboard help <kbd data-shortcut="?"></kbd></button><button id="search-menus">Search menus… <kbd data-shortcut="Alt /"></kbd></button></div></details><span class="spacer"></span><span id="comparison-line" class="comparison-line" hidden></span><strong id="result-count" aria-live="polite"></strong>
|
|
2463
|
+
<details id="active-filters" class="popup-menu" hidden>
|
|
2464
|
+
<summary aria-label="Active filters">
|
|
2465
|
+
<svg aria-hidden="true" width="16" height="16" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linejoin="round"><path d="M2 3h12L9.5 8v4l-3 1V8z"/></svg>
|
|
2466
|
+
</summary>
|
|
2467
|
+
<div class="popover"><strong>Active filters</strong><ul id="active-filter-list"></ul></div>
|
|
2468
|
+
</details></section>
|
|
2469
|
+
__TRACE_WORKSPACE__
|
|
2470
|
+
__TRACE_SYSTEMS__
|
|
2471
|
+
<div class="table-wrap"><table id="requirements-table" role="grid" aria-multiselectable="true"><caption>Requirements report</caption><colgroup id="column-widths"></colgroup><thead><tr id="heading-row" aria-rowindex="1"></tr><tr id="filter-row" class="filter-row" aria-rowindex="2"></tr></thead><tbody id="requirements-body"></tbody></table></div></main>
|
|
2472
|
+
<div id="row-drag-preview" aria-hidden="true" hidden></div>
|
|
2473
|
+
<div id="table-context-menu" class="popover" role="group" aria-label="Record actions" hidden></div>
|
|
2474
|
+
<div id="comment-hover" class="floating-popover comment-tooltip" role="tooltip" hidden></div><div id="quick-comment" class="floating-popover" role="dialog" aria-label="Add comment" hidden></div><div id="value-filter-popover" class="floating-popover value-filter" role="group" aria-label="Filter values" hidden></div>
|
|
2475
|
+
<section id="finding-popover" class="floating-popover" role="dialog" aria-labelledby="finding-popover-title" hidden><div class="popover-head"><h3 id="finding-popover-title" tabindex="-1"></h3><button type="button" class="popover-close" id="finding-popover-close" aria-label="Close findings">×</button></div><ul id="finding-popover-list"></ul><div id="finding-popover-actions" class="comment-actions"></div></section>
|
|
2476
|
+
<aside id="review-panel" class="review-panel" hidden aria-label="Comments"><div class="sidebar-resize" data-sidebar-resize role="separator" aria-orientation="vertical" aria-label="Resize comments sidebar"></div><div class="review-head"><button id="back-comments" hidden aria-label="Back to all comments">Back</button><h2 id="review-title">Comments</h2><button id="close-review" aria-label="Close comments">Close</button></div><div class="review-body"><label class="sr-only" for="comment-search">Search comments</label><input id="comment-search" class="comment-search" placeholder="Search comments…"><div class="comment-actions"><label class="sr-only" for="reviewer-filter">Reviewer</label><select id="reviewer-filter"><option value="">All reviewers</option></select><label class="sr-only" for="comment-column-filter">Column</label><select id="comment-column-filter"><option value="">All columns</option></select><label class="sr-only" for="comment-status-filter">Status</label><select id="comment-status-filter"><option value="">All statuses</option><option value="added">Added</option><option value="removed">Removed</option><option value="changed">Changed</option><option value="unchanged">Unchanged</option></select></div><div id="comment-counts" class="meta"></div><div id="comment-list"></div></div></aside>
|
|
2477
|
+
__TRACE_HTML__
|
|
2478
|
+
<aside id="quality-panel" class="review-panel" hidden aria-labelledby="quality-title">
|
|
2479
|
+
<div class="review-head"><h2 id="quality-title" tabindex="-1">Requirement quality</h2><button id="close-quality">Close</button></div>
|
|
2480
|
+
<div class="review-body">
|
|
2481
|
+
<div class="comment-actions"><button id="quality-settings">Quality settings…</button></div>
|
|
2482
|
+
<label><input type="checkbox" id="quality-only"> Show rows with findings</label>
|
|
2483
|
+
<label class="quality-dismissed-toggle"><input type="checkbox" id="quality-show-dismissed"> Show dismissed findings</label>
|
|
2484
|
+
<div id="quality-count" class="meta" role="status"></div>
|
|
2485
|
+
<div id="quality-findings"></div>
|
|
2486
|
+
<p class="meta">Writing guidance from <a href="https://www.nasa.gov/reference/appendix-c-how-to-write-a-good-requirement/" target="_blank" rel="noopener">NASA Appendix C</a>
|
|
2487
|
+
and the <a href="https://www.incose.org/wp-content/uploads/legacy/working-groups/requirements-wg/guidetowritingrequirements/incose_rwg_gtwr_v4_summary_sheet.pdf?sfvrsn=73644bc7_2" target="_blank" rel="noopener">INCOSE Guide to Writing Requirements summary</a>.</p>
|
|
2488
|
+
</div>
|
|
2489
|
+
</aside>
|
|
2490
|
+
<dialog id="quality-settings-dialog" class="help-dialog" aria-labelledby="quality-settings-title">
|
|
2491
|
+
<form id="quality-settings-form"><div class="help-head"><h2 id="quality-settings-title">Quality settings</h2><button type="button" id="quality-settings-cancel">Cancel</button></div>
|
|
2492
|
+
<div class="help-body"><label>Requirement column <select id="quality-column"></select></label>
|
|
2493
|
+
<label>Obligation keyword <input id="quality-obligation" placeholder="Leave blank to disable" maxlength="80"></label>
|
|
2494
|
+
<fieldset><legend>Required fields</legend><div id="quality-required-columns"></div></fieldset>
|
|
2495
|
+
<fieldset><legend>Enabled checks</legend><div id="quality-enabled-rules"></div></fieldset>
|
|
2496
|
+
<button type="submit" class="primary">Apply settings</button>
|
|
2497
|
+
</div>
|
|
2498
|
+
</form>
|
|
2499
|
+
</dialog>
|
|
2500
|
+
<dialog id="quality-dismiss-dialog" class="help-dialog" aria-labelledby="quality-dismiss-title">
|
|
2501
|
+
<form id="quality-dismiss-form"><div class="help-head"><h2 id="quality-dismiss-title">Dismiss finding</h2><button type="button" id="quality-dismiss-cancel">Cancel</button></div>
|
|
2502
|
+
<div class="help-body"><p id="quality-dismiss-description"></p>
|
|
2503
|
+
<label for="quality-dismiss-reason">Reason for accepting this wording</label>
|
|
2504
|
+
<textarea id="quality-dismiss-reason" required rows="3"></textarea>
|
|
2505
|
+
<p class="meta">This exception applies to this cell content and rule. Editing the content triggers a fresh review. Save a report copy to retain it.</p>
|
|
2506
|
+
<button type="submit" class="primary">Dismiss finding</button>
|
|
2507
|
+
</div>
|
|
2508
|
+
</form>
|
|
2509
|
+
</dialog>
|
|
2510
|
+
<dialog id="settings-dialog" class="help-dialog" aria-labelledby="settings-title"><div class="help-head"><h2 id="settings-title">Settings</h2><button id="close-settings">Done</button></div><div class="help-body"><label>Keyboard mode <select id="keyboard-mode"><option value="spreadsheet">Spreadsheet</option><option value="vim">Vim</option></select></label></div></dialog>
|
|
2511
|
+
<dialog id="command-search" class="help-dialog" aria-labelledby="command-title"><div class="help-head"><h2 id="command-title">Search menus</h2><button id="close-command-search">Close</button></div><div class="help-body"><label class="sr-only" for="command-query">Search menu items</label><input type="search" id="command-query" placeholder="Search menu items…"><div id="command-results"></div><p id="command-empty" hidden>No matching commands.</p></div></dialog>
|
|
2512
|
+
<dialog id="keyboard-help" class="help-dialog"><div class="help-head"><h2>Keyboard shortcuts</h2><button id="close-help">Close</button></div><div class="help-body"><p>Focus a table cell with <kbd>Tab</kbd>, then use:</p><table class="shortcut-table"><tbody><tr><th><kbd>Arrow keys</kbd> or <kbd>H</kbd><kbd>J</kbd><kbd>K</kbd><kbd>L</kbd></th><td>Move one cell</td></tr><tr><th><kbd>Home</kbd> / <kbd>End</kbd> or <kbd>0</kbd> / <kbd>$</kbd></th><td>First / last visible column</td></tr><tr><th><kbd>Ctrl</kbd>+<kbd>Home</kbd> / <kbd>Ctrl</kbd>+<kbd>End</kbd></th><td>First / last table corner. In Develop, Cmd also works and End skips the blank entry row.</td></tr><tr><th><kbd>g</kbd> / <kbd>G</kbd></th><td>First / last table row. In Develop, press <kbd>g</kbd> twice for the first row.</td></tr><tr><th><kbd>Page Up</kbd> / <kbd>Page Down</kbd></th><td>Move ten rows</td></tr><tr class="develop-only"><th><kbd>Tab</kbd> / <kbd>Shift</kbd>+<kbd>Tab</kbd></th><td>Next / previous cell, wrapping across rows. Tab leaves the grid at its edges.</td></tr><tr class="develop-only"><th><kbd>Ctrl/Cmd</kbd>+<kbd>Arrow</kbd></th><td>Jump to the end of a block of filled cells, across a gap to the next filled cell, or to the grid edge.</td></tr><tr class="develop-only"><th><kbd>Enter</kbd>, <kbd>F2</kbd>, or <kbd>i</kbd></th><td>Edit a non-ID cell. The i shortcut is for Vim mode.</td></tr><tr class="develop-only"><th><kbd>o</kbd> / <kbd>Shift</kbd>+<kbd>o</kbd></th><td>Insert a requirement below / above the selected requirement</td></tr><tr><th><kbd>C</kbd></th><td>Open comments for a non-ID cell</td></tr><tr><th><kbd>Ctrl/Cmd</kbd>+<kbd>Z</kbd> / <kbd>Ctrl/Cmd</kbd>+<kbd>Y</kbd></th><td>Undo / redo requirement edits in Develop mode. Ctrl/Cmd+Shift+Z also redoes.</td></tr><tr><th><kbd>/</kbd></th><td>Focus the selected column filter, or comment search when browsing comments</td></tr><tr><th><kbd>Down Arrow</kbd> or <kbd>Enter</kbd> in a filter</th><td>Move to that column in the first matching row</td></tr><tr><th><kbd>?</kbd></th><td>Open this help page</td></tr><tr><th><kbd>Escape</kbd></th><td>Cancel editing or close menus, popups, or the comments sidebar</td></tr></tbody></table><p>Click a menu name, then hover over another name to switch menus. Left and Right also switch menus. Down and Up move through items. Enter activates an item, Space toggles a checkbox, and Escape closes the menu. In Develop mode, choose View → Settings to switch between Spreadsheet and Vim shortcuts. Press Alt/Option+/ to search menus. Right-click a cell or press Shift+F10 to open its actions in Develop mode. In Spreadsheet mode, type on a selected editable cell to replace its value. In either mode, Tab or Shift+Tab applies the edit and moves to the next or previous cell. In Spreadsheet mode, Enter and Shift+Enter apply the edit and move down or up. Alt/Option+Enter inserts a newline, F2 starts with the caret at the end, and clicking another cell applies the edit. In Vim mode, Enter inserts a newline. Ctrl/Cmd+Enter applies the edit and stays on the cell in both modes. Column dividers can be dragged. Double-click a divider to auto-size the column on its left.</p></div></dialog>
|
|
2513
|
+
<script id="reqtable-data" type="application/json">__DATA__</script><script>__JS__</script></body></html>"""
|
|
2514
|
+
|
|
2515
|
+
|
|
2516
|
+
def _safe_json(data: dict[str, Any]) -> str:
|
|
2517
|
+
return (
|
|
2518
|
+
json.dumps(data, ensure_ascii=False, separators=(",", ":"))
|
|
2519
|
+
.replace("&", "\\u0026")
|
|
2520
|
+
.replace("<", "\\u003c")
|
|
2521
|
+
.replace(">", "\\u003e")
|
|
2522
|
+
.replace("\u2028", "\\u2028")
|
|
2523
|
+
.replace("\u2029", "\\u2029")
|
|
2524
|
+
)
|
|
2525
|
+
|
|
2526
|
+
|
|
2527
|
+
def render_report(data: dict[str, Any]) -> str:
|
|
2528
|
+
meta = data["meta"]
|
|
2529
|
+
title = html.escape(meta["title"])
|
|
2530
|
+
document_mode = meta.get("documentMode", "review")
|
|
2531
|
+
description = (
|
|
2532
|
+
f"Diff: {html.escape(meta['oldFilename'])} → {html.escape(meta['newFilename'])} · Generated {html.escape(meta['generated'])}"
|
|
2533
|
+
if meta["mode"] == "diff"
|
|
2534
|
+
else f"Source: {html.escape(meta['newFilename'])} · Generated {html.escape(meta['generated'])}"
|
|
2535
|
+
)
|
|
2536
|
+
summary = ""
|
|
2537
|
+
if meta["mode"] == "diff":
|
|
2538
|
+
summary = "".join(
|
|
2539
|
+
f'<span class="badge {name}">{name.title()}: {meta["counts"][name]}</span>'
|
|
2540
|
+
for name in ("added", "removed", "changed", "unchanged")
|
|
2541
|
+
)
|
|
2542
|
+
if meta["ignoredColumns"]:
|
|
2543
|
+
summary += (
|
|
2544
|
+
'<span class="badge">Ignored for change detection: '
|
|
2545
|
+
+ html.escape(", ".join(meta["ignoredColumns"]))
|
|
2546
|
+
+ "</span>"
|
|
2547
|
+
)
|
|
2548
|
+
embedded = {key: value for key, value in data.items() if key != "rows"}
|
|
2549
|
+
embedded["formatVersion"] = 2
|
|
2550
|
+
if meta["mode"] == "diff":
|
|
2551
|
+
embedded["diffStatus"] = {row["id"]: row["status"] for row in data["rows"]}
|
|
2552
|
+
traceability = data["options"].get("traceability", False)
|
|
2553
|
+
has_package = bool(data.get("package"))
|
|
2554
|
+
trace_js = TRACE_MODEL_JS + TRACE_UI_JS if traceability else "const trace=null;\n"
|
|
2555
|
+
return (
|
|
2556
|
+
TEMPLATE.replace("__TRACE_MENU__", TRACE_MENU if traceability else "")
|
|
2557
|
+
.replace("__TRACE_HTML__", TRACE_HTML + GLOSSARY_HTML if traceability else "")
|
|
2558
|
+
.replace("__TRACE_WORKSPACE__", TRACE_WORKSPACE if traceability else "")
|
|
2559
|
+
.replace("__TRACE_SYSTEMS__", TRACE_SYSTEMS if traceability else "")
|
|
2560
|
+
.replace("__DRAFTS_HTML__", DRAFTS_HTML)
|
|
2561
|
+
.replace("__PACKAGE_HTML__", PACKAGE_HTML if has_package else "")
|
|
2562
|
+
.replace("__TITLE__", title)
|
|
2563
|
+
.replace(
|
|
2564
|
+
"__DOCUMENT_MODE_LABEL__",
|
|
2565
|
+
"Develop mode" if document_mode == "develop" else "Review mode",
|
|
2566
|
+
)
|
|
2567
|
+
.replace("__DOCUMENT_MODE__", document_mode)
|
|
2568
|
+
.replace("__META__", description)
|
|
2569
|
+
.replace("__SUMMARY__", summary)
|
|
2570
|
+
.replace(
|
|
2571
|
+
"__INITIALS__", html.escape(data["options"]["reviewerInitials"], quote=True)
|
|
2572
|
+
)
|
|
2573
|
+
.replace(
|
|
2574
|
+
"__CSS__",
|
|
2575
|
+
CSS
|
|
2576
|
+
+ DRAFTS_CSS
|
|
2577
|
+
+ (PACKAGE_CSS if has_package else "")
|
|
2578
|
+
+ (TRACE_CSS + GLOSSARY_CSS if traceability else ""),
|
|
2579
|
+
)
|
|
2580
|
+
.replace("__DATA__", _safe_json(embedded))
|
|
2581
|
+
.replace(
|
|
2582
|
+
"__JS__",
|
|
2583
|
+
COMPARISON_JS
|
|
2584
|
+
+ GATE_CHECKS_JS
|
|
2585
|
+
+ POPOVER_JS
|
|
2586
|
+
+ JS
|
|
2587
|
+
+ FILTER_JS
|
|
2588
|
+
+ WINDOW_JS
|
|
2589
|
+
+ VALUE_EDIT_JS
|
|
2590
|
+
+ trace_js
|
|
2591
|
+
+ (PACKAGE_JS if has_package else "const renderPackage=null;\n")
|
|
2592
|
+
+ DRAFTS_JS
|
|
2593
|
+
+ INITIAL_RENDER_JS,
|
|
2594
|
+
)
|
|
2595
|
+
)
|