@sdxc/ui 2026.11.10 → 2026.11.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +92 -45
- package/dist/app/app-shell-toggle.d.ts +2 -0
- package/dist/app/app-shell-toggle.js +5 -2
- package/dist/app/app-shell.d.ts +25 -1
- package/dist/app/app-shell.js +73 -38
- package/dist/app/auto-refresh.d.ts +2 -0
- package/dist/app/auto-refresh.js +3 -3
- package/dist/app/behaviors/refresh-schedule.d.ts +8 -3
- package/dist/app/behaviors/refresh-schedule.js +4 -3
- package/dist/app/board.d.ts +123 -0
- package/dist/app/board.js +224 -0
- package/dist/app/chart.d.ts +2 -2
- package/dist/app/chart.js +7 -3
- package/dist/app/check-runs.d.ts +116 -0
- package/dist/app/check-runs.js +201 -0
- package/dist/app/code-view.d.ts +172 -0
- package/dist/app/code-view.js +414 -0
- package/dist/app/command-palette.d.ts +38 -3
- package/dist/app/command-palette.js +53 -5
- package/dist/app/contribution-graph.d.ts +106 -0
- package/dist/app/contribution-graph.js +289 -0
- package/dist/app/detail-sheet.d.ts +7 -0
- package/dist/app/detail-sheet.js +7 -7
- package/dist/app/diff.d.ts +200 -0
- package/dist/app/diff.js +702 -0
- package/dist/app/filter-bar.d.ts +20 -0
- package/dist/app/filter-bar.js +35 -15
- package/dist/app/filter-menu.d.ts +144 -0
- package/dist/app/filter-menu.js +480 -0
- package/dist/app/gantt.d.ts +108 -0
- package/dist/app/gantt.js +420 -0
- package/dist/app/index.d.ts +19 -0
- package/dist/app/index.js +19 -0
- package/dist/app/log-viewer.d.ts +120 -0
- package/dist/app/log-viewer.js +384 -0
- package/dist/app/merge-box.d.ts +97 -0
- package/dist/app/merge-box.js +227 -0
- package/dist/app/mixins/app-shell-controls.d.ts +4 -1
- package/dist/app/mixins/app-shell-controls.js +64 -4
- package/dist/app/mixins/auto-refresh.d.ts +5 -2
- package/dist/app/mixins/auto-refresh.js +9 -3
- package/dist/app/mixins/close-popover-on-submit.d.ts +16 -0
- package/dist/app/mixins/close-popover-on-submit.js +32 -0
- package/dist/app/mixins/code-view-selection.d.ts +60 -0
- package/dist/app/mixins/code-view-selection.js +276 -0
- package/dist/app/mixins/command-palette.d.ts +15 -4
- package/dist/app/mixins/command-palette.js +94 -6
- package/dist/app/mixins/contribution-graph-keys.d.ts +19 -0
- package/dist/app/mixins/contribution-graph-keys.js +155 -0
- package/dist/app/mixins/diff-interactions.d.ts +72 -0
- package/dist/app/mixins/diff-interactions.js +269 -0
- package/dist/app/mixins/filter-menu-keys.d.ts +41 -0
- package/dist/app/mixins/filter-menu-keys.js +91 -0
- package/dist/app/mixins/gantt-today.d.ts +17 -0
- package/dist/app/mixins/gantt-today.js +50 -0
- package/dist/app/mixins/log-viewer.d.ts +29 -0
- package/dist/app/mixins/log-viewer.js +333 -0
- package/dist/app/mixins/optimistic-toggle-sync.d.ts +5 -0
- package/dist/app/mixins/optimistic-toggle-sync.js +25 -1
- package/dist/app/mixins/save-bar-sync.d.ts +7 -1
- package/dist/app/mixins/save-bar-sync.js +23 -4
- package/dist/app/mixins/save-status-sync.js +23 -1
- package/dist/app/mixins/split-view.js +1 -1
- package/dist/app/mixins/submit-on-close.d.ts +17 -0
- package/dist/app/mixins/submit-on-close.js +52 -0
- package/dist/app/mixins/tree-filter.d.ts +44 -0
- package/dist/app/mixins/tree-filter.js +111 -0
- package/dist/app/mixins/tree-navigation.d.ts +50 -0
- package/dist/app/mixins/tree-navigation.js +216 -0
- package/dist/app/optimistic-toggle.d.ts +8 -0
- package/dist/app/optimistic-toggle.js +3 -2
- package/dist/app/page-header.d.ts +18 -3
- package/dist/app/page-header.js +105 -50
- package/dist/app/review-thread.d.ts +115 -0
- package/dist/app/review-thread.js +116 -0
- package/dist/app/save-bar.d.ts +5 -0
- package/dist/app/save-bar.js +1 -1
- package/dist/app/settings-layout.d.ts +5 -0
- package/dist/app/settings-layout.js +5 -5
- package/dist/app/skeleton.d.ts +9 -0
- package/dist/app/skeleton.js +28 -0
- package/dist/app/split-view.d.ts +4 -0
- package/dist/app/split-view.js +3 -3
- package/dist/app/styles/code-tokens.d.ts +24 -0
- package/dist/app/styles/code-tokens.js +47 -0
- package/dist/app/tab-bar.d.ts +59 -0
- package/dist/app/tab-bar.js +111 -0
- package/dist/app/tree.d.ts +111 -14
- package/dist/app/tree.js +202 -15
- package/dist/app/utils/ansi.d.ts +55 -0
- package/dist/app/utils/ansi.js +157 -0
- package/dist/app/utils/diff-rows.d.ts +82 -0
- package/dist/app/utils/diff-rows.js +209 -0
- package/dist/app/utils/fuzzy-path.d.ts +58 -0
- package/dist/app/utils/fuzzy-path.js +202 -0
- package/dist/app/utils/line-range.d.ts +48 -0
- package/dist/app/utils/line-range.js +61 -0
- package/dist/app/utils/log-lines.d.ts +107 -0
- package/dist/app/utils/log-lines.js +170 -0
- package/dist/app/utils/tree-filter.d.ts +19 -0
- package/dist/app/utils/tree-filter.js +26 -0
- package/dist/app/view-options.d.ts +2 -0
- package/dist/app/view-options.js +2 -2
- package/dist/chat/activity.d.ts +72 -0
- package/dist/chat/activity.js +184 -0
- package/dist/chat/composer-submit.d.ts +38 -0
- package/dist/chat/composer-submit.js +44 -0
- package/dist/chat/composer.d.ts +47 -0
- package/dist/chat/composer.js +100 -0
- package/dist/chat/index.d.ts +6 -0
- package/dist/chat/index.js +6 -0
- package/dist/chat/mixins/composer-send.d.ts +32 -0
- package/dist/chat/mixins/composer-send.js +121 -0
- package/dist/chat/mixins/reveal-stream.d.ts +68 -0
- package/dist/chat/mixins/reveal-stream.js +184 -0
- package/dist/chat/mixins/stream-target.d.ts +18 -0
- package/dist/chat/mixins/stream-target.js +38 -0
- package/dist/components/button.js +7 -1
- package/dist/components/character-count.d.ts +44 -0
- package/dist/components/character-count.js +68 -0
- package/dist/components/index.d.ts +2 -0
- package/dist/components/index.js +2 -0
- package/dist/components/label-chip.d.ts +42 -0
- package/dist/components/label-chip.js +86 -0
- package/dist/components/property-list.d.ts +9 -2
- package/dist/components/property-list.js +11 -6
- package/dist/components/textarea.js +6 -1
- package/dist/components/timeline.d.ts +62 -5
- package/dist/components/timeline.js +124 -5
- package/dist/docs/code-block.js +8 -31
- package/dist/docs/file-tree.js +3 -48
- package/dist/landing/case-study.d.ts +79 -0
- package/dist/landing/case-study.js +162 -0
- package/dist/landing/contributor-wall.d.ts +72 -0
- package/dist/landing/contributor-wall.js +129 -0
- package/dist/landing/countdown.d.ts +88 -0
- package/dist/landing/countdown.js +91 -0
- package/dist/landing/episode-player.d.ts +87 -0
- package/dist/landing/episode-player.js +113 -0
- package/dist/landing/faq-band.d.ts +3 -2
- package/dist/landing/faq-band.js +4 -3
- package/dist/landing/feature-band.d.ts +8 -0
- package/dist/landing/feature-band.js +9 -3
- package/dist/landing/index.d.ts +9 -0
- package/dist/landing/index.js +9 -0
- package/dist/landing/landing-header.js +15 -4
- package/dist/landing/mixins/countdown-tick.d.ts +29 -0
- package/dist/landing/mixins/countdown-tick.js +65 -0
- package/dist/landing/mixins/usage-estimate-live.d.ts +32 -0
- package/dist/landing/mixins/usage-estimate-live.js +120 -0
- package/dist/landing/phone-fan.d.ts +38 -0
- package/dist/landing/phone-fan.js +89 -0
- package/dist/landing/phone-frame.d.ts +48 -0
- package/dist/landing/phone-frame.js +41 -0
- package/dist/landing/price-list.d.ts +68 -0
- package/dist/landing/price-list.js +125 -0
- package/dist/landing/scroll-scene.d.ts +59 -0
- package/dist/landing/scroll-scene.js +70 -0
- package/dist/landing/sponsor-wall.d.ts +30 -6
- package/dist/landing/sponsor-wall.js +70 -14
- package/dist/landing/typed-terminal.d.ts +24 -6
- package/dist/landing/typed-terminal.js +22 -14
- package/dist/landing/usage-estimate.d.ts +127 -0
- package/dist/landing/usage-estimate.js +164 -0
- package/dist/landing/utils/countdown.d.ts +33 -0
- package/dist/landing/utils/countdown.js +42 -0
- package/dist/landing/utils/pause-toggle.d.ts +2 -1
- package/dist/mixins/character-count.d.ts +62 -0
- package/dist/mixins/character-count.js +139 -0
- package/dist/mixins/index.d.ts +6 -2
- package/dist/mixins/index.js +6 -2
- package/dist/mixins/invoker-fields.d.ts +18 -0
- package/dist/mixins/invoker-fields.js +60 -0
- package/dist/mixins/media-sync.d.ts +58 -0
- package/dist/mixins/media-sync.js +102 -0
- package/dist/mixins/menu-keys.d.ts +11 -0
- package/dist/mixins/menu-keys.js +79 -70
- package/dist/mixins/sortable.d.ts +96 -0
- package/dist/mixins/sortable.js +433 -0
- package/dist/utils/code-lines.d.ts +26 -0
- package/dist/utils/code-lines.js +29 -0
- package/dist/utils/file-icon.d.ts +31 -0
- package/dist/utils/file-icon.js +60 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.js +2 -0
- package/dist/utils/write-cookie.d.ts +15 -15
- package/dist/utils/write-cookie.js +10 -16
- package/dist/video/index.d.ts +11 -0
- package/dist/video/index.js +11 -0
- package/dist/video/mixins/video-player-sync.d.ts +27 -0
- package/dist/video/mixins/video-player-sync.js +413 -0
- package/dist/video/utils/timeline.d.ts +55 -0
- package/dist/video/utils/timeline.js +90 -0
- package/dist/video/video-player.d.ts +261 -0
- package/dist/video/video-player.js +927 -0
- package/package.json +6 -3
|
@@ -0,0 +1,414 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "remix/component/jsx-runtime";
|
|
2
|
+
import { tokenize } from "@sdxc/highlight";
|
|
3
|
+
import { EllipsisIcon } from "@sdxc/icons";
|
|
4
|
+
import { visuallyHidden } from "@sdxc/u/a11y";
|
|
5
|
+
import { bg, borderEdge, fg, outline } from "@sdxc/u/color";
|
|
6
|
+
import { rounded } from "@sdxc/u/effects";
|
|
7
|
+
import { mergeMix, raw } from "@sdxc/u/general";
|
|
8
|
+
import { center, flexWrap, hstack, relative, shrink } from "@sdxc/u/layout";
|
|
9
|
+
import { bs, is, minIs, pb, pi } from "@sdxc/u/size";
|
|
10
|
+
import { when } from "@sdxc/u/state";
|
|
11
|
+
import { tabularNums, text } from "@sdxc/u/typography";
|
|
12
|
+
import { clientEntry } from "remix/component";
|
|
13
|
+
import { Menu } from "../components/menu.js";
|
|
14
|
+
import { panelChrome } from "../styles/panel-chrome.js";
|
|
15
|
+
import { codeLines } from "../utils/code-lines.js";
|
|
16
|
+
import { formatRelativeTime } from "../utils/relative-time.js";
|
|
17
|
+
import { codeViewSelection } from "./mixins/code-view-selection.js";
|
|
18
|
+
import { CODE_TOKEN_PALETTE, codeTokenRules } from "./styles/code-tokens.js";
|
|
19
|
+
import { lineLink, lineRangeQuery } from "./utils/line-range.js";
|
|
20
|
+
export { lineLink, lineRangeHash, lineRangeQuery, parseLineRange } from "./utils/line-range.js";
|
|
21
|
+
/**
|
|
22
|
+
* Lines per `<tbody>` chunk. Each chunk is skipped by `content-visibility` until it nears
|
|
23
|
+
* the screen, so a long file lays out only what is read, and find-in-page and `#L` anchors
|
|
24
|
+
* still reach every line because every line is in the document.
|
|
25
|
+
*/
|
|
26
|
+
const DEFAULT_CHUNK_SIZE = 200;
|
|
27
|
+
/** Height of one unwrapped line, which a skipped chunk reserves per line. */
|
|
28
|
+
const LINE_HEIGHT = "var(--code-view-line-height, 1.25rem)";
|
|
29
|
+
/** Container width below which lines wrap and blame keeps only its age. */
|
|
30
|
+
const WRAP_WIDTH = "40rem";
|
|
31
|
+
/** Width of the blame column on a wide view. */
|
|
32
|
+
const BLAME_WIDTH = "var(--code-view-blame-width, 22rem)";
|
|
33
|
+
/** Width of the blame column once the view wraps. */
|
|
34
|
+
const BLAME_NARROW_WIDTH = "5rem";
|
|
35
|
+
/** Number of steps the age strip runs from oldest to newest. */
|
|
36
|
+
const AGE_STEPS = 5;
|
|
37
|
+
/** FNV-1a offset basis, the starting state of the hash that names a view from its path. */
|
|
38
|
+
const FNV_OFFSET = 0x811c9dc5;
|
|
39
|
+
/** FNV-1a prime, which spreads each character through the hash. */
|
|
40
|
+
const FNV_PRIME = 0x01000193;
|
|
41
|
+
/**
|
|
42
|
+
* Counts a file the way its header reports it, dropping a single trailing newline as the
|
|
43
|
+
* view does, so "49 lines" matches the last number drawn.
|
|
44
|
+
*
|
|
45
|
+
* @param code The file's source.
|
|
46
|
+
* @returns Lines, lines of code and bytes, for the app to phrase in its own locale.
|
|
47
|
+
* @example let { lines, loc, bytes } = codeStats(source); t("file.meta", { lines, loc, size: formatBytes(bytes) })
|
|
48
|
+
*/
|
|
49
|
+
export function codeStats(code) {
|
|
50
|
+
let lines = splitSource(code);
|
|
51
|
+
return {
|
|
52
|
+
lines: lines.length,
|
|
53
|
+
loc: lines.filter((line) => line.trim() !== "").length,
|
|
54
|
+
bytes: new TextEncoder().encode(code).length,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
/** The source's lines, without the empty one a trailing newline would add. */
|
|
58
|
+
function splitSource(code) {
|
|
59
|
+
return code.replace(/\r?\n$/, "").split(/\r?\n/);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Without script `selected` and `#Ln` paint the cited lines, and each number links to `?L=n#Ln`;
|
|
63
|
+
* mapping `@sdxc/ui/app/code-view` runs {@link CodeViewSelection} for ranges, the menu and `y`.
|
|
64
|
+
* Set `--code-view-font-size`, `-line-height`, `-blame-width`, `-selected` and `--code-age-1`–`5`.
|
|
65
|
+
*
|
|
66
|
+
* @param handle Runtime handle carrying the view's props.
|
|
67
|
+
* @returns The render function producing the view.
|
|
68
|
+
* @example
|
|
69
|
+
* <CodeView path="app/routes.ts" language="ts" code={source} selected={parseLineRange(url.searchParams.get("L"))} permalink={`/blob/${sha}/app/routes.ts`} labels={labels}>
|
|
70
|
+
* <CodeView.Header meta={t("file.meta", codeStats(source))}>{actions}</CodeView.Header>
|
|
71
|
+
* </CodeView>
|
|
72
|
+
* @example
|
|
73
|
+
* <CodeView path="app/routes.ts" language="ts" code={source} blame={hunks} labels={labels} />
|
|
74
|
+
*/
|
|
75
|
+
export function CodeView(handle) {
|
|
76
|
+
return () => {
|
|
77
|
+
let { blame, children, chunkSize = DEFAULT_CHUNK_SIZE, code, id, issueHref, labels, language, lineHref = lineLink, locale, mix, now, path, permalink, selected, tokens, ...rest } = handle.props;
|
|
78
|
+
let source = code.replace(/\r?\n$/, "");
|
|
79
|
+
let runs = tokens ?? (language ? tokenize(source, language) : [{ type: "plain", value: source }]);
|
|
80
|
+
let lines = codeLines(runs);
|
|
81
|
+
let count = splitSource(code).length;
|
|
82
|
+
while (lines.length < count)
|
|
83
|
+
lines.push([]);
|
|
84
|
+
lines.length = count;
|
|
85
|
+
let viewId = id ?? stableId(path);
|
|
86
|
+
let digits = Math.max(2, String(count).length);
|
|
87
|
+
let blameCells = blame && blame.length > 0
|
|
88
|
+
? blameSegments(blame, count, chunkSize, { now, locale })
|
|
89
|
+
: undefined;
|
|
90
|
+
let hasBlame = blameCells !== undefined;
|
|
91
|
+
return (_jsxs("div", { ...rest, id: viewId, "data-slot": "code-view", "data-language": language, "data-selection": selected ? lineRangeQuery(selected) : undefined, mix: mergeMix([
|
|
92
|
+
panelChrome(),
|
|
93
|
+
relative(),
|
|
94
|
+
minIs(0),
|
|
95
|
+
raw({
|
|
96
|
+
container: "code-view / inline-size",
|
|
97
|
+
overflow: "clip",
|
|
98
|
+
backgroundColor: "var(--code-view-bg)",
|
|
99
|
+
"--code-view-bg": "var(--ui-surface-raised, var(--ui-bg, Canvas))",
|
|
100
|
+
}),
|
|
101
|
+
], mix), children: [children, _jsx("div", { "data-slot": "code-view-scroll", dir: "ltr", mix: [raw({ overflowX: "auto", overscrollBehaviorInline: "contain" })], children: _jsx("table", { "aria-label": path, mix: [tableRules(digits, hasBlame)], children: chunkRanges(count, chunkSize).map(({ start, end }) => (_jsx("tbody", { "data-chunk": start, mix: [
|
|
102
|
+
raw({
|
|
103
|
+
containIntrinsicBlockSize: `auto calc(${end - start + 1} * ${LINE_HEIGHT})`,
|
|
104
|
+
}),
|
|
105
|
+
], children: chunkRows(lines, start, end, selected, lineHref, blameCells) }))) }) }), _jsx(CodeViewSelection, { menuId: `${viewId}-line-menu`, permalink: permalink, issueHref: issueHref, labels: labels })] }));
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Every rule the table and its rows follow, set once on the table so no row carries a
|
|
110
|
+
* class of its own. Chunks lay their rows out on one grid of fixed tracks (blame, number,
|
|
111
|
+
* code), so the columns line up across chunks while each chunk can be skipped on its own.
|
|
112
|
+
*
|
|
113
|
+
* @param digits Digits the widest line number needs.
|
|
114
|
+
* @param hasBlame Whether rows carry a leading blame column.
|
|
115
|
+
*/
|
|
116
|
+
function tableRules(digits, hasBlame) {
|
|
117
|
+
let numberWidth = `calc(${digits}ch + 2.25rem)`;
|
|
118
|
+
let selected = "color-mix(in oklab, var(--ui-brand-fg) 14%, var(--code-view-bg))";
|
|
119
|
+
let band = {
|
|
120
|
+
backgroundColor: `var(--code-view-selected, ${selected})`,
|
|
121
|
+
};
|
|
122
|
+
let bar = { boxShadow: "inset 2px 0 0 var(--ui-brand-fg)" };
|
|
123
|
+
return raw({
|
|
124
|
+
display: "block",
|
|
125
|
+
inlineSize: "max-content",
|
|
126
|
+
minInlineSize: "100%",
|
|
127
|
+
margin: 0,
|
|
128
|
+
borderCollapse: "collapse",
|
|
129
|
+
fontFamily: "var(--ui-font-mono, ui-monospace, monospace)",
|
|
130
|
+
fontVariantLigatures: "none",
|
|
131
|
+
fontSize: "var(--code-view-font-size, 0.75rem)",
|
|
132
|
+
lineHeight: LINE_HEIGHT,
|
|
133
|
+
color: "var(--ui-neutral-fg-emphasis)",
|
|
134
|
+
tabSize: 4,
|
|
135
|
+
"--code-view-blame": hasBlame ? BLAME_WIDTH : "0px",
|
|
136
|
+
"& > tbody": {
|
|
137
|
+
display: "grid",
|
|
138
|
+
gridTemplateColumns: hasBlame
|
|
139
|
+
? `var(--code-view-blame) ${numberWidth} 1fr`
|
|
140
|
+
: `${numberWidth} 1fr`,
|
|
141
|
+
paddingBlock: 0,
|
|
142
|
+
contentVisibility: "auto",
|
|
143
|
+
},
|
|
144
|
+
"& > tbody:first-child": { paddingBlockStart: "0.5rem" },
|
|
145
|
+
"& > tbody:last-child": { paddingBlockEnd: "0.5rem" },
|
|
146
|
+
"& tr": { display: "contents" },
|
|
147
|
+
"& td": { padding: 0, verticalAlign: "top" },
|
|
148
|
+
"& td:nth-last-child(2)": {
|
|
149
|
+
gridColumn: hasBlame ? 2 : 1,
|
|
150
|
+
position: "sticky",
|
|
151
|
+
insetInlineStart: "var(--code-view-blame)",
|
|
152
|
+
zIndex: 1,
|
|
153
|
+
backgroundColor: "var(--code-view-bg)",
|
|
154
|
+
userSelect: "none",
|
|
155
|
+
},
|
|
156
|
+
"& td:last-child": {
|
|
157
|
+
gridColumn: hasBlame ? 3 : 2,
|
|
158
|
+
paddingInline: "0.75rem 1.5rem",
|
|
159
|
+
whiteSpace: "pre",
|
|
160
|
+
},
|
|
161
|
+
"& a[data-line-number]": {
|
|
162
|
+
display: "block",
|
|
163
|
+
paddingInline: "1.5rem 0.75rem",
|
|
164
|
+
textAlign: "end",
|
|
165
|
+
color: "var(--ui-neutral-fg-muted)",
|
|
166
|
+
textDecoration: "none",
|
|
167
|
+
cursor: "pointer",
|
|
168
|
+
outline: "none",
|
|
169
|
+
},
|
|
170
|
+
"& a[data-line-number]::before": { content: "attr(data-line-number)" },
|
|
171
|
+
"& a[data-line-number]:hover": { color: "var(--ui-neutral-fg-emphasis)" },
|
|
172
|
+
"& a[data-line-number]:focus-visible": {
|
|
173
|
+
color: "var(--ui-neutral-fg-emphasis)",
|
|
174
|
+
boxShadow: "inset 0 0 0 2px var(--ui-brand-ring, var(--ui-brand-fg))",
|
|
175
|
+
borderRadius: "var(--ui-radius-sm, 0.25rem)",
|
|
176
|
+
},
|
|
177
|
+
"& tr[data-selected] > td:not([data-blame])": band,
|
|
178
|
+
"& tr[data-selected] > td:nth-last-child(2)": bar,
|
|
179
|
+
"& tr[data-selected] a[data-line-number]": { color: "var(--ui-brand-fg)" },
|
|
180
|
+
[`:not([data-selection-live]) > [data-slot="code-view-scroll"] > & tr:has(> td > a:target) > td:not([data-blame])`]: band,
|
|
181
|
+
[`:not([data-selection-live]) > [data-slot="code-view-scroll"] > & tr:has(> td > a:target) > td:nth-last-child(2)`]: bar,
|
|
182
|
+
"& td[data-blame]": {
|
|
183
|
+
gridColumn: 1,
|
|
184
|
+
display: "flex",
|
|
185
|
+
flexDirection: "column",
|
|
186
|
+
minInlineSize: 0,
|
|
187
|
+
paddingInline: "0.75rem",
|
|
188
|
+
boxShadow: "inset 0 1px 0 var(--ui-neutral-border)",
|
|
189
|
+
borderInlineEnd: "3px solid var(--code-view-age)",
|
|
190
|
+
fontFamily: "var(--ui-font-sans, system-ui, sans-serif)",
|
|
191
|
+
fontSize: "0.75rem",
|
|
192
|
+
lineHeight: LINE_HEIGHT,
|
|
193
|
+
color: "var(--ui-neutral-fg-muted)",
|
|
194
|
+
whiteSpace: "nowrap",
|
|
195
|
+
},
|
|
196
|
+
"& td[data-blame][data-rows='1']": {
|
|
197
|
+
flexDirection: "row",
|
|
198
|
+
alignItems: "baseline",
|
|
199
|
+
gap: "0.5rem",
|
|
200
|
+
},
|
|
201
|
+
"& td[data-blame][data-rows='1'] > [data-slot='blame-subject']": { flex: "1 1 auto" },
|
|
202
|
+
"& td[data-blame][data-rows='1'] > [data-slot='blame-meta']": { flex: "none" },
|
|
203
|
+
"& td[data-blame][data-rows='1'] [data-slot='blame-author']": { display: "none" },
|
|
204
|
+
"& tbody:first-child > tr:first-child > td[data-blame], & td[data-blame][data-continued]": {
|
|
205
|
+
boxShadow: "none",
|
|
206
|
+
},
|
|
207
|
+
"& [data-slot='blame-subject']": {
|
|
208
|
+
overflow: "hidden",
|
|
209
|
+
textOverflow: "ellipsis",
|
|
210
|
+
color: "var(--ui-neutral-fg-emphasis)",
|
|
211
|
+
textDecoration: "none",
|
|
212
|
+
},
|
|
213
|
+
"& [data-slot='blame-subject']:hover": { textDecoration: "underline" },
|
|
214
|
+
"& [data-slot='blame-meta']": {
|
|
215
|
+
display: "flex",
|
|
216
|
+
gap: "0.5rem",
|
|
217
|
+
overflow: "hidden",
|
|
218
|
+
textOverflow: "ellipsis",
|
|
219
|
+
},
|
|
220
|
+
...ageRules(),
|
|
221
|
+
...codeTokenRules(),
|
|
222
|
+
[`@container code-view (max-width: ${WRAP_WIDTH})`]: {
|
|
223
|
+
"&": { inlineSize: "100%", "--code-view-blame": hasBlame ? BLAME_NARROW_WIDTH : "0px" },
|
|
224
|
+
"& > tbody": {
|
|
225
|
+
gridTemplateColumns: hasBlame
|
|
226
|
+
? `var(--code-view-blame) calc(${digits}ch + 1.25rem) minmax(0, 1fr)`
|
|
227
|
+
: `${numberWidth} minmax(0, 1fr)`,
|
|
228
|
+
},
|
|
229
|
+
"& td:last-child": { whiteSpace: "pre-wrap", overflowWrap: "anywhere", minInlineSize: 0 },
|
|
230
|
+
"& a[data-line-number]": hasBlame
|
|
231
|
+
? { paddingInline: "0.5rem 0.75rem" }
|
|
232
|
+
: { paddingInlineStart: "1.25rem" },
|
|
233
|
+
"& td[data-blame]": { paddingInline: "0.5rem" },
|
|
234
|
+
"& [data-slot='blame-subject'], & [data-slot='blame-author']": { display: "none" },
|
|
235
|
+
},
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* The age strip's colors, one `--code-view-age` per step from oldest (1) to newest
|
|
240
|
+
* ({@link AGE_STEPS}). An app sets `--code-age-1` through `--code-age-5` to art-direct it;
|
|
241
|
+
* the fallback deepens the brand tone toward the newest step in either scheme.
|
|
242
|
+
*/
|
|
243
|
+
function ageRules() {
|
|
244
|
+
let rules = {};
|
|
245
|
+
for (let step = 1; step <= AGE_STEPS; step += 1) {
|
|
246
|
+
let strength = Math.round((step / AGE_STEPS) * 100);
|
|
247
|
+
rules[`& td[data-blame][data-age="${step}"]`] = {
|
|
248
|
+
"--code-view-age": `var(--code-age-${step}, color-mix(in oklab, var(--ui-brand-fg) ${strength}%, var(--code-view-bg)))`,
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
return rules;
|
|
252
|
+
}
|
|
253
|
+
/** One chunk's first and last line, both counted from 1. */
|
|
254
|
+
function chunkRanges(count, size) {
|
|
255
|
+
let ranges = [];
|
|
256
|
+
for (let start = 1; start <= count; start += size) {
|
|
257
|
+
ranges.push({ start, end: Math.min(count, start + size - 1) });
|
|
258
|
+
}
|
|
259
|
+
return ranges;
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Splits every hunk at chunk edges, since a cell spans rows only inside its own chunk, and
|
|
263
|
+
* keys each piece by its first line. A hunk's age step ranks its commit's date between the
|
|
264
|
+
* oldest and newest commit in the file.
|
|
265
|
+
*/
|
|
266
|
+
function blameSegments(hunks, count, size, format) {
|
|
267
|
+
let times = hunks.map((hunk) => new Date(hunk.commit.date).getTime());
|
|
268
|
+
let oldest = Math.min(...times);
|
|
269
|
+
let span = Math.max(...times) - oldest;
|
|
270
|
+
let cells = new Map();
|
|
271
|
+
for (let [index, hunk] of hunks.entries()) {
|
|
272
|
+
let age = span <= 0 ? AGE_STEPS : 1 + Math.round(((times[index] - oldest) / span) * (AGE_STEPS - 1));
|
|
273
|
+
let time = formatRelativeTime(hunk.commit.date, format);
|
|
274
|
+
let end = Math.min(hunk.end, count);
|
|
275
|
+
for (let start = Math.max(1, hunk.start); start <= end;) {
|
|
276
|
+
let chunkEnd = Math.ceil(start / size) * size;
|
|
277
|
+
let pieceEnd = Math.min(end, chunkEnd);
|
|
278
|
+
cells.set(start, {
|
|
279
|
+
commit: hunk.commit,
|
|
280
|
+
rows: pieceEnd - start + 1,
|
|
281
|
+
continued: start !== Math.max(1, hunk.start),
|
|
282
|
+
age,
|
|
283
|
+
time,
|
|
284
|
+
});
|
|
285
|
+
start = pieceEnd + 1;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
return cells;
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* The rows of one chunk. Rows are plain local render values built in one loop: a file can
|
|
292
|
+
* hold ten thousand of them, and each row is four elements (the row, two cells, the number
|
|
293
|
+
* link) plus its runs, with no component instance or class of its own. A row that starts a
|
|
294
|
+
* blame piece leads with the hunk's cell (subject, author, age), set in code lines so the
|
|
295
|
+
* code never stretches, and a one-line hunk keeps subject and age on its one line; a
|
|
296
|
+
* continued piece draws only its strip.
|
|
297
|
+
*/
|
|
298
|
+
function chunkRows(lines, start, end, selected, lineHref, blame) {
|
|
299
|
+
let rows = [];
|
|
300
|
+
let focusLine = selected?.start ?? 1;
|
|
301
|
+
for (let line = start; line <= end; line += 1) {
|
|
302
|
+
let cell = blame?.get(line);
|
|
303
|
+
let isSelected = selected !== undefined && line >= selected.start && line <= selected.end;
|
|
304
|
+
let blameData = cell ? (_jsxs("td", { "data-blame": "", "data-age": cell.age, "data-continued": cell.continued ? "" : undefined, "data-rows": cell.rows === 1 ? "1" : undefined, rowSpan: cell.rows, mix: [raw({ gridRowEnd: `span ${cell.rows}` })], children: [cell.continued ? null : (_jsx("a", { href: cell.commit.href, "data-slot": "blame-subject", title: cell.commit.subject, children: cell.commit.subject })), cell.continued ? null : (_jsxs("span", { "data-slot": "blame-meta", children: [_jsx("span", { "data-slot": "blame-author", children: cell.commit.author }), _jsx("time", { dateTime: cell.time.dateTime, title: cell.time.title, children: cell.time.text })] }))] })) : null;
|
|
305
|
+
rows.push(_jsxs("tr", { "data-selected": isSelected ? "" : undefined, children: [blameData, _jsx("td", { children: _jsx("a", { id: `L${line}`, href: lineHref(line), "data-line-number": line, tabIndex: line === focusLine ? 0 : -1 }) }), _jsx("td", { children: renderRuns(lines[line - 1] ?? []) })] }));
|
|
306
|
+
}
|
|
307
|
+
return rows;
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* A line's runs: plain text stays a text node, and each highlighted run is one
|
|
311
|
+
* `span.token.<type>` the table's rules color. Neighbouring runs of one type merge first, so
|
|
312
|
+
* no line holds two nodes where one would do.
|
|
313
|
+
*/
|
|
314
|
+
function renderRuns(runs) {
|
|
315
|
+
let merged = [];
|
|
316
|
+
for (let run of runs) {
|
|
317
|
+
let type = CODE_TOKEN_PALETTE[run.type] ? run.type : "plain";
|
|
318
|
+
let last = merged[merged.length - 1];
|
|
319
|
+
if (last && last.type === type)
|
|
320
|
+
last.value += run.value;
|
|
321
|
+
else
|
|
322
|
+
merged.push({ type, value: run.value });
|
|
323
|
+
}
|
|
324
|
+
return merged.map((run) => run.type === "plain" ? run.value : _jsx("span", { className: `token ${run.type}`, children: run.value }));
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* An element id derived from the path, so a cached page keeps the same ids on every render
|
|
328
|
+
* of the same file.
|
|
329
|
+
*/
|
|
330
|
+
function stableId(value) {
|
|
331
|
+
let hash = FNV_OFFSET;
|
|
332
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
333
|
+
hash ^= value.charCodeAt(index);
|
|
334
|
+
hash = Math.imul(hash, FNV_PRIME);
|
|
335
|
+
}
|
|
336
|
+
return `code-view-${(hash >>> 0).toString(36)}`;
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* Renders the file's header: its facts (lines, size) on the start side in tabular figures,
|
|
340
|
+
* and its actions on the end side, wrapping under the facts on a narrow view.
|
|
341
|
+
*
|
|
342
|
+
* @param handle Runtime handle carrying the header's props.
|
|
343
|
+
* @returns The render function producing the header.
|
|
344
|
+
* @example <CodeView.Header meta={t("file.meta", { lines: 49, loc: 42, size: "1.75 KB" })}><LinkButton href={rawHref}>{t("file.raw")}</LinkButton></CodeView.Header>
|
|
345
|
+
*/
|
|
346
|
+
CodeView.Header = function CodeViewHeader(handle) {
|
|
347
|
+
return () => {
|
|
348
|
+
let { children, meta, mix, ...rest } = handle.props;
|
|
349
|
+
return (_jsxs("div", { ...rest, "data-slot": "code-view-header", mix: mergeMix([
|
|
350
|
+
hstack({ gap: 3, align: "center", justify: "between" }),
|
|
351
|
+
flexWrap("wrap"),
|
|
352
|
+
pi(4),
|
|
353
|
+
pb(2),
|
|
354
|
+
raw({ minBlockSize: "2.75rem" }),
|
|
355
|
+
bg("neutral.bg-tint"),
|
|
356
|
+
borderEdge("block-end", { color: "neutral.border", width: 1, style: "solid" }),
|
|
357
|
+
], mix), children: [_jsx("span", { "data-slot": "code-view-meta", mix: [text("xs"), fg("neutral.muted"), tabularNums(), minIs(0)], children: meta }), children ? (_jsx("span", { mix: [hstack({ gap: 2, align: "center" }), flexWrap("wrap")], children: children })) : null] }));
|
|
358
|
+
};
|
|
359
|
+
};
|
|
360
|
+
/**
|
|
361
|
+
* Renders the age strip's legend: the older label, one swatch per step in the strip's own
|
|
362
|
+
* colors, and the newer label.
|
|
363
|
+
*
|
|
364
|
+
* @param handle Runtime handle carrying the legend's props.
|
|
365
|
+
* @returns The render function producing the legend.
|
|
366
|
+
* @example <CodeView.AgeLegend labels={{ older: t("blame.older"), newer: t("blame.newer") }} />
|
|
367
|
+
*/
|
|
368
|
+
CodeView.AgeLegend = function CodeViewAgeLegend(handle) {
|
|
369
|
+
return () => {
|
|
370
|
+
let { labels, mix, ...rest } = handle.props;
|
|
371
|
+
let steps = Array.from({ length: AGE_STEPS }, (_, index) => index + 1);
|
|
372
|
+
return (_jsxs("div", { ...rest, "data-slot": "code-view-age-legend", mix: mergeMix([hstack({ gap: 1.5, align: "center" }), text("xs"), fg("neutral.muted")], mix), children: [_jsx("span", { children: labels.older }), _jsx("span", { "aria-hidden": "true", mix: [hstack({ gap: 0.5 })], children: steps.map((step) => (_jsx("span", { "data-age": step, mix: [
|
|
373
|
+
is(2.5),
|
|
374
|
+
bs(2.5),
|
|
375
|
+
rounded("sm"),
|
|
376
|
+
raw({
|
|
377
|
+
backgroundColor: `var(--code-age-${step}, color-mix(in oklab, var(--ui-brand-fg) ${Math.round((step / AGE_STEPS) * 100)}%, var(--ui-surface-raised, Canvas)))`,
|
|
378
|
+
}),
|
|
379
|
+
] }))) }), _jsx("span", { children: labels.newer })] }));
|
|
380
|
+
};
|
|
381
|
+
};
|
|
382
|
+
/**
|
|
383
|
+
* Client island every {@link CodeView} renders once: the line menu (Copy line, Copy
|
|
384
|
+
* permalink, Reference in new issue) and the `codeViewSelection()` mixin that owns the
|
|
385
|
+
* view's selection. Loads from `@sdxc/ui/app/code-view#CodeViewSelection` once the app's
|
|
386
|
+
* browser entry maps it; until then each number links to its own `?L=` address.
|
|
387
|
+
*/
|
|
388
|
+
export const CodeViewSelection = clientEntry("@sdxc/ui/app/code-view#CodeViewSelection", function CodeViewSelection(handle) {
|
|
389
|
+
return () => {
|
|
390
|
+
let { issueHref, labels, menuId, permalink } = handle.props;
|
|
391
|
+
return (_jsxs("div", { "data-slot": "code-view-line-menu", mix: [
|
|
392
|
+
codeViewSelection({ permalink, issueHref, labels }),
|
|
393
|
+
raw({
|
|
394
|
+
display: "none",
|
|
395
|
+
position: "absolute",
|
|
396
|
+
zIndex: 2,
|
|
397
|
+
insetBlockStart: `calc(var(--code-view-menu-top, 0px) + ${LINE_HEIGHT} / 2 - 0.625rem)`,
|
|
398
|
+
insetInlineStart: "calc(var(--code-view-menu-start, 0px) + 0.125rem)",
|
|
399
|
+
}),
|
|
400
|
+
when("[data-line-menu] > &", raw({ display: "block" })),
|
|
401
|
+
], children: [_jsx("button", { type: "button", popovertarget: menuId, "aria-label": labels.lineMenu, mix: [
|
|
402
|
+
center(),
|
|
403
|
+
shrink(),
|
|
404
|
+
is(5),
|
|
405
|
+
bs(5),
|
|
406
|
+
rounded("sm"),
|
|
407
|
+
fg("neutral"),
|
|
408
|
+
bg("neutral.bg-tint"),
|
|
409
|
+
raw({ border: "1px solid var(--ui-neutral-border)", padding: 0, cursor: "pointer" }),
|
|
410
|
+
when("&:hover", bg("neutral.bg-tint-hover")),
|
|
411
|
+
when("&:focus-visible", outline({ color: "brand.ring", offset: 2 })),
|
|
412
|
+
], children: _jsx(EllipsisIcon, { size: 14, "aria-hidden": "true" }) }), _jsxs(Menu, { id: menuId, "aria-label": labels.lineMenu, placement: "bottom-start", children: [_jsx(Menu.Item, { "data-action": "copy-line", children: labels.copyLine }), _jsx(Menu.Item, { "data-action": "copy-permalink", children: labels.copyPermalink }), issueHref && labels.referenceInNewIssue ? (_jsx(Menu.Item, { href: issueHref, "data-action": "reference", children: labels.referenceInNewIssue })) : null] }), _jsx("span", { role: "status", mix: [visuallyHidden()] })] }));
|
|
413
|
+
};
|
|
414
|
+
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The app's ⌘K command palette: a modal dialog the server fills with commands that act (links,
|
|
3
|
-
* buttons that submit a form or invoke a command, pages of further commands
|
|
4
|
-
*
|
|
3
|
+
* buttons that submit a form or invoke a command, pages of further commands, a fuzzy file finder)
|
|
4
|
+
* and a small island that filters them, moves the active row, and remembers recent picks.
|
|
5
5
|
*
|
|
6
6
|
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
7
|
* @copyright Sergio Xalambrí 2026
|
|
@@ -9,6 +9,8 @@
|
|
|
9
9
|
import type { EntryComponent, Handle, Props as TagProps, RemixNode } from "remix/component";
|
|
10
10
|
import { Button } from "../components/button.js";
|
|
11
11
|
import type { PaletteController } from "./mixins/command-palette.js";
|
|
12
|
+
export type { FuzzyMatch, FuzzySegment } from "./utils/fuzzy-path.js";
|
|
13
|
+
export { fuzzyFilter, fuzzyScore, fuzzySegments } from "./utils/fuzzy-path.js";
|
|
12
14
|
/**
|
|
13
15
|
* Types for {@link CommandPalette} and its parts.
|
|
14
16
|
*/
|
|
@@ -91,8 +93,35 @@ export declare namespace CommandPalette {
|
|
|
91
93
|
title: string;
|
|
92
94
|
/** Replaces the root placeholder while the page is open. */
|
|
93
95
|
placeholder?: string;
|
|
96
|
+
/**
|
|
97
|
+
* A combo or sequence that opens the palette straight on this page, e.g. `"t"`, listed in
|
|
98
|
+
* the help sheet under `title`.
|
|
99
|
+
*/
|
|
100
|
+
shortcut?: string;
|
|
94
101
|
children: RemixNode;
|
|
95
102
|
}
|
|
103
|
+
/** Props for {@link CommandPalette.Finder}. */
|
|
104
|
+
interface FinderProps {
|
|
105
|
+
/** The page id, which an item's `page` opens it by. */
|
|
106
|
+
id: string;
|
|
107
|
+
/** Shown beside the search field while the finder is open, e.g. "Go to File". */
|
|
108
|
+
title: string;
|
|
109
|
+
/** Replaces the root placeholder while the finder is open. */
|
|
110
|
+
placeholder?: string;
|
|
111
|
+
/**
|
|
112
|
+
* A combo or sequence that opens the palette straight on the finder, e.g. `"t"`, listed in
|
|
113
|
+
* the help sheet under `title`.
|
|
114
|
+
*/
|
|
115
|
+
shortcut?: string;
|
|
116
|
+
/** Every path to search, in the order shown before anything is typed. */
|
|
117
|
+
paths: readonly string[];
|
|
118
|
+
/** Where a path leads, with `{path}` replaced by its URI-encoded segments, e.g. `"/blob/main/{path}"`. */
|
|
119
|
+
href: string;
|
|
120
|
+
/** How many matches to list at once. @default 50 */
|
|
121
|
+
limit?: number;
|
|
122
|
+
/** The glyph before each path. @default a file icon */
|
|
123
|
+
icon?: RemixNode;
|
|
124
|
+
}
|
|
96
125
|
/** Props for {@link CommandPalette.Trigger}. */
|
|
97
126
|
interface TriggerProps extends Omit<Button.Props, "commandfor" | "command"> {
|
|
98
127
|
/** The palette's `id`. */
|
|
@@ -107,7 +136,7 @@ export declare namespace CommandPalette {
|
|
|
107
136
|
/**
|
|
108
137
|
* Renders the palette: a modal dialog 640px wide, 15% from the top, full width less a gutter on
|
|
109
138
|
* a phone. Without JavaScript a trigger still opens it and every command stays a working link
|
|
110
|
-
* or button; the island adds filtering, arrow keys, pages and
|
|
139
|
+
* or button; the island adds filtering, arrow keys, pages, the {@link CommandPalette.Finder} and ⌘K.
|
|
111
140
|
*
|
|
112
141
|
* @param handle Runtime handle carrying the palette's props.
|
|
113
142
|
* @returns The render function producing the palette.
|
|
@@ -117,12 +146,18 @@ export declare namespace CommandPalette {
|
|
|
117
146
|
* <CommandPalette.Item id="go-monitors" title="Go to Monitors" href="/monitors" shortcut="g m" />
|
|
118
147
|
* </CommandPalette.Group>
|
|
119
148
|
* </CommandPalette>
|
|
149
|
+
* @example
|
|
150
|
+
* <CommandPalette id="palette" labels={labels}>
|
|
151
|
+
* <CommandPalette.Item id="go-file" title="Go to File" page="files" />
|
|
152
|
+
* <CommandPalette.Finder id="files" title="Go to File" shortcut="t" paths={tree.paths} href="/blob/main/{path}" />
|
|
153
|
+
* </CommandPalette>
|
|
120
154
|
*/
|
|
121
155
|
export declare function CommandPalette(handle: Handle<CommandPalette.Props>): () => import("remix/component").RemixElement;
|
|
122
156
|
export declare namespace CommandPalette {
|
|
123
157
|
var Group: (handle: Handle<CommandPalette.GroupProps>) => () => import("remix/component").RemixElement;
|
|
124
158
|
var Item: (handle: Handle<CommandPalette.ItemProps>) => () => import("remix/component").RemixElement;
|
|
125
159
|
var Page: (handle: Handle<CommandPalette.PageProps>) => () => import("remix/component").RemixElement;
|
|
160
|
+
var Finder: (handle: Handle<CommandPalette.FinderProps>) => () => import("remix/component").RemixElement;
|
|
126
161
|
var Trigger: (handle: Handle<CommandPalette.TriggerProps>) => () => import("remix/component").RemixElement;
|
|
127
162
|
}
|
|
128
163
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "remix/component/jsx-runtime";
|
|
2
|
-
import { ChevronLeftIcon, ChevronRightIcon, SearchIcon } from "@sdxc/icons";
|
|
2
|
+
import { ChevronLeftIcon, ChevronRightIcon, FileIcon, SearchIcon } from "@sdxc/icons";
|
|
3
3
|
import { visuallyHidden } from "@sdxc/u/a11y";
|
|
4
4
|
import { bg, borderEdge, fg, outlineStyle } from "@sdxc/u/color";
|
|
5
5
|
import { rounded } from "@sdxc/u/effects";
|
|
@@ -16,9 +16,12 @@ import { Command } from "../components/command.js";
|
|
|
16
16
|
import { Keyboard } from "../components/keyboard.js";
|
|
17
17
|
import { Modal } from "../components/modal.js";
|
|
18
18
|
import { shortcutGlyphs } from "./behaviors/shortcuts.js";
|
|
19
|
-
import { PALETTE_CONTROL_ATTRIBUTE, PALETTE_GOTO_ATTRIBUTE, PALETTE_HINT_ATTRIBUTE, PALETTE_ITEM_ATTRIBUTE, PALETTE_PAGE_ATTRIBUTE, paletteController, } from "./mixins/command-palette.js";
|
|
19
|
+
import { PALETTE_CONTROL_ATTRIBUTE, PALETTE_FINDER_ATTRIBUTE, PALETTE_FINDER_PATH_ATTRIBUTE, PALETTE_FINDER_RESULTS_ATTRIBUTE, PALETTE_FINDER_ROW_ATTRIBUTE, PALETTE_GOTO_ATTRIBUTE, PALETTE_HINT_ATTRIBUTE, PALETTE_ITEM_ATTRIBUTE, PALETTE_PAGE_ATTRIBUTE, PALETTE_PAGE_SHORTCUT_ATTRIBUTE, paletteController, } from "./mixins/command-palette.js";
|
|
20
|
+
export { fuzzyFilter, fuzzyScore, fuzzySegments } from "./utils/fuzzy-path.js";
|
|
20
21
|
/** The combo that opens the palette when none is given. */
|
|
21
22
|
const DEFAULT_SHORTCUT = "mod+k";
|
|
23
|
+
/** How many paths the finder lists at once when `limit` is omitted. */
|
|
24
|
+
const DEFAULT_FINDER_LIMIT = 50;
|
|
22
25
|
/**
|
|
23
26
|
* Renders a shortcut's caps, marked with its combo so the island reprints them for a keyboard
|
|
24
27
|
* without the Apple glyphs.
|
|
@@ -29,7 +32,7 @@ function Hint(handle) {
|
|
|
29
32
|
/**
|
|
30
33
|
* Renders the palette: a modal dialog 640px wide, 15% from the top, full width less a gutter on
|
|
31
34
|
* a phone. Without JavaScript a trigger still opens it and every command stays a working link
|
|
32
|
-
* or button; the island adds filtering, arrow keys, pages and
|
|
35
|
+
* or button; the island adds filtering, arrow keys, pages, the {@link CommandPalette.Finder} and ⌘K.
|
|
33
36
|
*
|
|
34
37
|
* @param handle Runtime handle carrying the palette's props.
|
|
35
38
|
* @returns The render function producing the palette.
|
|
@@ -39,6 +42,11 @@ function Hint(handle) {
|
|
|
39
42
|
* <CommandPalette.Item id="go-monitors" title="Go to Monitors" href="/monitors" shortcut="g m" />
|
|
40
43
|
* </CommandPalette.Group>
|
|
41
44
|
* </CommandPalette>
|
|
45
|
+
* @example
|
|
46
|
+
* <CommandPalette id="palette" labels={labels}>
|
|
47
|
+
* <CommandPalette.Item id="go-file" title="Go to File" page="files" />
|
|
48
|
+
* <CommandPalette.Finder id="files" title="Go to File" shortcut="t" paths={tree.paths} href="/blob/main/{path}" />
|
|
49
|
+
* </CommandPalette>
|
|
42
50
|
*/
|
|
43
51
|
export function CommandPalette(handle) {
|
|
44
52
|
return () => {
|
|
@@ -154,10 +162,50 @@ function ItemControl(handle) {
|
|
|
154
162
|
*/
|
|
155
163
|
CommandPalette.Page = function CommandPalettePage(handle) {
|
|
156
164
|
return () => {
|
|
157
|
-
let { id, title, placeholder, children } = handle.props;
|
|
158
|
-
return (_jsx("div", { role: "group", "aria-label": title, hidden: true, "data-palette-title": title, "data-palette-placeholder": placeholder, [PALETTE_PAGE_ATTRIBUTE]: id, children: children }));
|
|
165
|
+
let { id, title, placeholder, shortcut, children } = handle.props;
|
|
166
|
+
return (_jsx("div", { role: "group", "aria-label": title, hidden: true, "data-palette-title": title, "data-palette-placeholder": placeholder, [PALETTE_PAGE_ATTRIBUTE]: id, [PALETTE_PAGE_SHORTCUT_ATTRIBUTE]: shortcut, children: children }));
|
|
159
167
|
};
|
|
160
168
|
};
|
|
169
|
+
/**
|
|
170
|
+
* Renders a "Go to file" page: the {@link CommandPaletteController} island ranks `paths` with
|
|
171
|
+
* {@link fuzzyFilter} per keystroke and lists the best `limit` as links, matched characters bold.
|
|
172
|
+
* Results appear once the island loads; a server's `/find?q=` page ranks the same way for no script.
|
|
173
|
+
*
|
|
174
|
+
* @param handle Runtime handle carrying the finder's props.
|
|
175
|
+
* @returns The render function producing the finder's page.
|
|
176
|
+
* @example
|
|
177
|
+
* <CommandPalette.Finder id="files" title="Go to File" shortcut="t" paths={tree.paths} href="/blob/main/{path}" />
|
|
178
|
+
* @example
|
|
179
|
+
* <CommandPalette.Item id="go-file" title="Go to File" page="files" />
|
|
180
|
+
*/
|
|
181
|
+
CommandPalette.Finder = function CommandPaletteFinder(handle) {
|
|
182
|
+
return () => {
|
|
183
|
+
let { id, title, placeholder, shortcut, paths, href, limit, icon } = handle.props;
|
|
184
|
+
return (_jsx(CommandPalette.Page, { id: id, title: title, placeholder: placeholder, shortcut: shortcut, children: _jsxs("div", { [PALETTE_FINDER_ATTRIBUTE]: paths.join("\n"),
|
|
185
|
+
"data-palette-finder-href": href,
|
|
186
|
+
"data-palette-finder-limit": String(limit ?? DEFAULT_FINDER_LIMIT), mix: [when("& mark", [bg("transparent"), fg("neutral.emphasis"), weight("semibold")])], children: [_jsx("template", { [PALETTE_FINDER_ROW_ATTRIBUTE]: "", children: _jsx(FinderRow, { id: `${id}-row`, path: "{path}", href: "#", icon: icon }) }), _jsx("div", { [PALETTE_FINDER_RESULTS_ATTRIBUTE]: "" })] }) }));
|
|
187
|
+
};
|
|
188
|
+
};
|
|
189
|
+
/**
|
|
190
|
+
* Renders one finder result: a 36px row whose link leads to the path, with the matched
|
|
191
|
+
* characters as `<mark>`s the finder sets in bold. The island clones it per result.
|
|
192
|
+
*/
|
|
193
|
+
function FinderRow(handle) {
|
|
194
|
+
return () => {
|
|
195
|
+
let { id, path, href, icon } = handle.props;
|
|
196
|
+
return (_jsx(Command.Item, { id: id, value: path, [PALETTE_ITEM_ATTRIBUTE]: id, mix: [bs("2.25rem"), p(0), pi(0)], children: _jsxs("a", { [PALETTE_CONTROL_ATTRIBUTE]: "", href: href, tabindex: -1, mix: [
|
|
197
|
+
hstack({ gap: 2, align: "center" }),
|
|
198
|
+
is("full"),
|
|
199
|
+
bs("full"),
|
|
200
|
+
pi(2),
|
|
201
|
+
fg("inherit"),
|
|
202
|
+
textDecoration("none"),
|
|
203
|
+
text("sm"),
|
|
204
|
+
cursor("default"),
|
|
205
|
+
outlineStyle("none"),
|
|
206
|
+
], children: [_jsx("span", { "aria-hidden": "true", mix: [hstack({ align: "center" }), fg("neutral.muted")], children: icon ?? _jsx(FileIcon, { size: 14 }) }), _jsx("span", { [PALETTE_FINDER_PATH_ATTRIBUTE]: "", mix: [truncate(), fg("neutral.muted")], children: path })] }) }));
|
|
207
|
+
};
|
|
208
|
+
}
|
|
161
209
|
/**
|
|
162
210
|
* Renders the button that opens the palette, styled as a quiet search field with the key that
|
|
163
211
|
* opens it: one route for the pointer, and the place a reader learns the key.
|