xtralab 0.13.1 → 0.14.1
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 +1 -1
- package/lib/about/icons.d.ts +7 -0
- package/lib/about/icons.js +11 -0
- package/lib/about/index.d.ts +13 -0
- package/lib/about/index.js +81 -0
- package/lib/index.js +4 -0
- package/lib/menuBar/icons.d.ts +6 -0
- package/lib/menuBar/icons.js +13 -0
- package/lib/menuBar/index.d.ts +15 -0
- package/lib/menuBar/index.js +164 -0
- package/lib/omnibox/index.d.ts +5 -3
- package/lib/omnibox/index.js +17 -4
- package/lib/omnibox/model.d.ts +6 -0
- package/lib/omnibox/model.js +67 -12
- package/lib/omnibox/recents.d.ts +9 -2
- package/lib/omnibox/recents.js +40 -15
- package/lib/omnibox/widget.d.ts +6 -0
- package/lib/omnibox/widget.js +3 -2
- package/logo.svg +63 -0
- package/package.json +4 -2
- package/schema/about.json +24 -0
- package/schema/menu-bar.json +37 -0
- package/src/about/icons.ts +13 -0
- package/src/about/index.tsx +125 -0
- package/src/index.ts +4 -0
- package/src/menuBar/icons.ts +14 -0
- package/src/menuBar/index.ts +195 -0
- package/src/omnibox/index.ts +19 -4
- package/src/omnibox/model.ts +73 -11
- package/src/omnibox/recents.ts +53 -25
- package/src/omnibox/widget.tsx +9 -1
- package/src/svg.d.ts +4 -0
- package/style/about.css +66 -0
- package/style/index.css +1 -0
- package/style/index.js +1 -0
package/src/omnibox/index.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { ICommandPalette } from '@jupyterlab/apputils';
|
|
|
6
6
|
import { ISettingRegistry } from '@jupyterlab/settingregistry';
|
|
7
7
|
import { IStateDB } from '@jupyterlab/statedb';
|
|
8
8
|
import { ITranslator, nullTranslator } from '@jupyterlab/translation';
|
|
9
|
-
import { Widget } from '@lumino/widgets';
|
|
9
|
+
import { CommandPalette, Widget } from '@lumino/widgets';
|
|
10
10
|
|
|
11
11
|
import { IAgentRegistry } from '../launcher/tokens';
|
|
12
12
|
|
|
@@ -19,9 +19,11 @@ const PLUGIN_ID = 'xtralab:omnibox';
|
|
|
19
19
|
/**
|
|
20
20
|
* The omnibox: a single launcher overlay that fuzzy-searches workspace files
|
|
21
21
|
* (via jupyterlab-quickopen's gitignore-aware endpoint) and JupyterLab
|
|
22
|
-
* commands
|
|
23
|
-
*
|
|
24
|
-
*
|
|
22
|
+
* commands (the command palette's entries plus registry commands the palette
|
|
23
|
+
* doesn't list), and routes a typed prompt to one of the configured agents
|
|
24
|
+
* (running it in a fresh terminal through the launcher's
|
|
25
|
+
* `xtralab:start-agent:<id>` commands). It is opened by the top-bar command
|
|
26
|
+
* bar.
|
|
25
27
|
*
|
|
26
28
|
* Commands run and files opened through the overlay are remembered (persisted
|
|
27
29
|
* in the state database) and offered again at the top while the query is
|
|
@@ -55,6 +57,18 @@ const plugin: JupyterFrontEndPlugin<IOmnibox> = {
|
|
|
55
57
|
const trans = (translator ?? nullTranslator).load('jupyterlab');
|
|
56
58
|
const placeholder = trans.__('Search files and commands, or ask an agent…');
|
|
57
59
|
|
|
60
|
+
// The palette's items carry per-item args (e.g. one "Use Theme: …" per
|
|
61
|
+
// theme) that a raw command-registry scan can't see, but `ICommandPalette`
|
|
62
|
+
// exposes no item list and the widget itself is unreachable through the
|
|
63
|
+
// shell (`LabShell.add` defers it until layout restore, after which the
|
|
64
|
+
// modal setting re-parents it out of the left area). The wrapper's
|
|
65
|
+
// `_palette` field is private in TypeScript only, so read it guarded.
|
|
66
|
+
const paletteItems = (): ReadonlyArray<CommandPalette.IItem> => {
|
|
67
|
+
const widget = (palette as unknown as { _palette?: unknown } | null)
|
|
68
|
+
?._palette;
|
|
69
|
+
return widget instanceof CommandPalette ? [...widget.items] : [];
|
|
70
|
+
};
|
|
71
|
+
|
|
58
72
|
const recents = new OmniboxRecents({ state });
|
|
59
73
|
|
|
60
74
|
// Restore the persisted recents only after the configured cap is known:
|
|
@@ -100,6 +114,7 @@ const plugin: JupyterFrontEndPlugin<IOmnibox> = {
|
|
|
100
114
|
close();
|
|
101
115
|
const widget = new OmniboxWidget({
|
|
102
116
|
commands,
|
|
117
|
+
paletteItems: paletteItems(),
|
|
103
118
|
docRegistry,
|
|
104
119
|
agents: agentRegistry ? agentRegistry.agents : [],
|
|
105
120
|
placeholder,
|
package/src/omnibox/model.ts
CHANGED
|
@@ -3,6 +3,8 @@ import type { TranslationBundle } from '@jupyterlab/translation';
|
|
|
3
3
|
import { fileIcon, LabIcon } from '@jupyterlab/ui-components';
|
|
4
4
|
import { StringExt } from '@lumino/algorithm';
|
|
5
5
|
import type { CommandRegistry } from '@lumino/commands';
|
|
6
|
+
import type { ReadonlyPartialJSONObject } from '@lumino/coreutils';
|
|
7
|
+
import type { CommandPalette } from '@lumino/widgets';
|
|
6
8
|
|
|
7
9
|
import type { IAgent } from '../launcher/agents';
|
|
8
10
|
import { agentCommandId } from '../launcher/tokens';
|
|
@@ -61,6 +63,11 @@ interface IOmniboxSections {
|
|
|
61
63
|
interface IComputeOptions {
|
|
62
64
|
query: string;
|
|
63
65
|
commands: CommandRegistry;
|
|
66
|
+
/**
|
|
67
|
+
* The command palette's items, whose labels are computed with each item's
|
|
68
|
+
* args — the only form in which entries like "Use Theme: …" exist.
|
|
69
|
+
*/
|
|
70
|
+
paletteItems: ReadonlyArray<CommandPalette.IItem>;
|
|
64
71
|
docRegistry: DocumentRegistry;
|
|
65
72
|
agents: IAgent[];
|
|
66
73
|
files: string[];
|
|
@@ -131,12 +138,13 @@ export function computeSections(options: IComputeOptions): IOmniboxSections {
|
|
|
131
138
|
function executeCommand(
|
|
132
139
|
commands: CommandRegistry,
|
|
133
140
|
recents: OmniboxRecents | null,
|
|
134
|
-
id: string
|
|
141
|
+
id: string,
|
|
142
|
+
args?: ReadonlyPartialJSONObject
|
|
135
143
|
): void {
|
|
136
144
|
void commands
|
|
137
|
-
.execute(id)
|
|
145
|
+
.execute(id, args)
|
|
138
146
|
.then(() => {
|
|
139
|
-
recents?.touch('command', id);
|
|
147
|
+
recents?.touch('command', id, args);
|
|
140
148
|
})
|
|
141
149
|
.catch(reason => {
|
|
142
150
|
console.error(`xtralab omnibox: command "${id}" failed`, reason);
|
|
@@ -169,17 +177,18 @@ function openFile(
|
|
|
169
177
|
*/
|
|
170
178
|
function commandDisplay(
|
|
171
179
|
commands: CommandRegistry,
|
|
172
|
-
id: string
|
|
180
|
+
id: string,
|
|
181
|
+
args?: ReadonlyPartialJSONObject
|
|
173
182
|
): { label: string; caption: string } | null {
|
|
174
183
|
if (!commands.hasCommand(id)) {
|
|
175
184
|
return null;
|
|
176
185
|
}
|
|
177
186
|
try {
|
|
178
|
-
const label = commands.label(id);
|
|
179
|
-
if (!label || !commands.isVisible(id)) {
|
|
187
|
+
const label = commands.label(id, args);
|
|
188
|
+
if (!label || !commands.isVisible(id, args)) {
|
|
180
189
|
return null;
|
|
181
190
|
}
|
|
182
|
-
return { label, caption: commands.caption(id) };
|
|
191
|
+
return { label, caption: commands.caption(id, args) };
|
|
183
192
|
} catch {
|
|
184
193
|
return null;
|
|
185
194
|
}
|
|
@@ -207,18 +216,18 @@ function buildRecentItems(
|
|
|
207
216
|
const items: IOmniboxItem[] = [];
|
|
208
217
|
for (const entry of recents.entries(kind)) {
|
|
209
218
|
if (entry.kind === 'command') {
|
|
210
|
-
const display = commandDisplay(commands, entry.id);
|
|
219
|
+
const display = commandDisplay(commands, entry.id, entry.args);
|
|
211
220
|
if (!display) {
|
|
212
221
|
continue;
|
|
213
222
|
}
|
|
214
223
|
items.push({
|
|
215
224
|
kind: 'command',
|
|
216
|
-
key: `recent:command:${entry.id}`,
|
|
225
|
+
key: `recent:command:${entry.id}:${JSON.stringify(entry.args ?? null)}`,
|
|
217
226
|
label: display.label,
|
|
218
227
|
matchIndices: [],
|
|
219
228
|
caption: display.caption || undefined,
|
|
220
229
|
execute: () => {
|
|
221
|
-
executeCommand(commands, recents, entry.id);
|
|
230
|
+
executeCommand(commands, recents, entry.id, entry.args);
|
|
222
231
|
}
|
|
223
232
|
});
|
|
224
233
|
} else {
|
|
@@ -240,11 +249,64 @@ function buildRecentItems(
|
|
|
240
249
|
return items;
|
|
241
250
|
}
|
|
242
251
|
|
|
252
|
+
/**
|
|
253
|
+
* Match the query against the palette's items first — their labels carry each
|
|
254
|
+
* item's args (one "Use Theme: …" per theme, one row per font-size key), which
|
|
255
|
+
* a raw registry scan can never produce — then against registry commands the
|
|
256
|
+
* palette doesn't present. Palette-covered ids are skipped in the registry
|
|
257
|
+
* pass so a command never also surfaces under its argless label.
|
|
258
|
+
*/
|
|
243
259
|
function matchCommands(options: IComputeOptions, term: string): IOmniboxItem[] {
|
|
244
|
-
const { commands, recents } = options;
|
|
260
|
+
const { commands, paletteItems, recents } = options;
|
|
245
261
|
const query = term.toLowerCase();
|
|
246
262
|
const scored: Array<{ score: number; item: IOmniboxItem }> = [];
|
|
263
|
+
const inPalette = new Set<string>();
|
|
264
|
+
const seenKeys = new Set<string>();
|
|
265
|
+
for (const item of paletteItems) {
|
|
266
|
+
inPalette.add(item.command);
|
|
267
|
+
const { command: id, args } = item;
|
|
268
|
+
let label = '';
|
|
269
|
+
let visible = true;
|
|
270
|
+
let caption = '';
|
|
271
|
+
try {
|
|
272
|
+
// An item's accessors can throw if the command assumes a context (e.g.
|
|
273
|
+
// an active notebook) the omnibox doesn't provide; skip those.
|
|
274
|
+
label = item.label;
|
|
275
|
+
visible = item.isVisible;
|
|
276
|
+
caption = item.caption;
|
|
277
|
+
} catch {
|
|
278
|
+
continue;
|
|
279
|
+
}
|
|
280
|
+
if (!label || !visible) {
|
|
281
|
+
continue;
|
|
282
|
+
}
|
|
283
|
+
const key = `command:${id}:${JSON.stringify(args)}`;
|
|
284
|
+
if (seenKeys.has(key)) {
|
|
285
|
+
continue;
|
|
286
|
+
}
|
|
287
|
+
seenKeys.add(key);
|
|
288
|
+
const match = StringExt.matchSumOfSquares(label.toLowerCase(), query);
|
|
289
|
+
if (!match) {
|
|
290
|
+
continue;
|
|
291
|
+
}
|
|
292
|
+
scored.push({
|
|
293
|
+
score: match.score,
|
|
294
|
+
item: {
|
|
295
|
+
kind: 'command',
|
|
296
|
+
key,
|
|
297
|
+
label,
|
|
298
|
+
matchIndices: match.indices,
|
|
299
|
+
caption: caption || undefined,
|
|
300
|
+
execute: () => {
|
|
301
|
+
executeCommand(commands, recents, id, args);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
});
|
|
305
|
+
}
|
|
247
306
|
for (const id of commands.listCommands()) {
|
|
307
|
+
if (inPalette.has(id)) {
|
|
308
|
+
continue;
|
|
309
|
+
}
|
|
248
310
|
let label = '';
|
|
249
311
|
let visible = true;
|
|
250
312
|
let caption = '';
|
package/src/omnibox/recents.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { IStateDB } from '@jupyterlab/statedb';
|
|
2
|
-
import type {
|
|
2
|
+
import type { ReadonlyPartialJSONObject } from '@lumino/coreutils';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Kinds of omnibox results whose uses are recorded.
|
|
@@ -15,6 +15,19 @@ interface IRecentEntry {
|
|
|
15
15
|
* The command id, or the workspace-relative file path.
|
|
16
16
|
*/
|
|
17
17
|
id: string;
|
|
18
|
+
/**
|
|
19
|
+
* Arguments the command ran with, for palette-style entries whose label
|
|
20
|
+
* and behavior depend on them (e.g. one "Use Theme: …" per theme).
|
|
21
|
+
*/
|
|
22
|
+
args?: ReadonlyPartialJSONObject;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Identity of an entry: two uses only match when kind, id and args all do,
|
|
27
|
+
* so runs of one command with different args stay distinct entries.
|
|
28
|
+
*/
|
|
29
|
+
function entryKey(entry: IRecentEntry): string {
|
|
30
|
+
return `${entry.kind}\0${entry.id}\0${JSON.stringify(entry.args ?? null)}`;
|
|
18
31
|
}
|
|
19
32
|
|
|
20
33
|
/**
|
|
@@ -65,13 +78,15 @@ export class OmniboxRecents {
|
|
|
65
78
|
}
|
|
66
79
|
|
|
67
80
|
/**
|
|
68
|
-
* Record a use of `id
|
|
81
|
+
* Record a use of `id` (with the args it ran with, if any), moving it to
|
|
82
|
+
* the front of its kind's list.
|
|
69
83
|
*/
|
|
70
|
-
touch(kind: RecentKind, id: string): void {
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
);
|
|
74
|
-
|
|
84
|
+
touch(kind: RecentKind, id: string, args?: ReadonlyPartialJSONObject): void {
|
|
85
|
+
const entry: IRecentEntry =
|
|
86
|
+
args === undefined ? { kind, id } : { kind, id, args };
|
|
87
|
+
const key = entryKey(entry);
|
|
88
|
+
const rest = this._entries.filter(existing => entryKey(existing) !== key);
|
|
89
|
+
this._entries = this._trim([entry, ...rest]);
|
|
75
90
|
this._save();
|
|
76
91
|
}
|
|
77
92
|
|
|
@@ -90,23 +105,35 @@ export class OmniboxRecents {
|
|
|
90
105
|
return;
|
|
91
106
|
}
|
|
92
107
|
const persisted: IRecentEntry[] = Array.isArray(fetched)
|
|
93
|
-
? fetched.filter(
|
|
94
|
-
(entry
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
108
|
+
? fetched.filter((entry): entry is IRecentEntry => {
|
|
109
|
+
if (!entry || typeof entry !== 'object') {
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
const candidate = entry as IRecentEntry;
|
|
113
|
+
if (candidate.kind !== 'command' && candidate.kind !== 'file') {
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
if (typeof candidate.id !== 'string') {
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
const args: unknown = candidate.args;
|
|
120
|
+
return (
|
|
121
|
+
args === undefined ||
|
|
122
|
+
(typeof args === 'object' && args !== null && !Array.isArray(args))
|
|
123
|
+
);
|
|
124
|
+
})
|
|
101
125
|
: [];
|
|
126
|
+
const known = new Set(this._entries.map(entryKey));
|
|
102
127
|
const merged = [...this._entries];
|
|
103
128
|
for (const entry of persisted) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
129
|
+
const key = entryKey(entry);
|
|
130
|
+
if (!known.has(key)) {
|
|
131
|
+
known.add(key);
|
|
132
|
+
merged.push(
|
|
133
|
+
entry.args === undefined
|
|
134
|
+
? { kind: entry.kind, id: entry.id }
|
|
135
|
+
: { kind: entry.kind, id: entry.id, args: entry.args }
|
|
136
|
+
);
|
|
110
137
|
}
|
|
111
138
|
}
|
|
112
139
|
this._entries = this._trim(merged);
|
|
@@ -128,10 +155,11 @@ export class OmniboxRecents {
|
|
|
128
155
|
if (!this._state) {
|
|
129
156
|
return;
|
|
130
157
|
}
|
|
131
|
-
const value = this._entries.map<
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
158
|
+
const value = this._entries.map<ReadonlyPartialJSONObject>(entry =>
|
|
159
|
+
entry.args === undefined
|
|
160
|
+
? { kind: entry.kind, id: entry.id }
|
|
161
|
+
: { kind: entry.kind, id: entry.id, args: entry.args }
|
|
162
|
+
);
|
|
135
163
|
this._state.save(STATE_KEY, value).catch(reason => {
|
|
136
164
|
console.error('xtralab omnibox: failed to save recents', reason);
|
|
137
165
|
});
|
package/src/omnibox/widget.tsx
CHANGED
|
@@ -2,6 +2,7 @@ import type { DocumentRegistry } from '@jupyterlab/docregistry';
|
|
|
2
2
|
import type { TranslationBundle } from '@jupyterlab/translation';
|
|
3
3
|
import { LabIcon, ReactWidget } from '@jupyterlab/ui-components';
|
|
4
4
|
import type { CommandRegistry } from '@lumino/commands';
|
|
5
|
+
import type { CommandPalette } from '@lumino/widgets';
|
|
5
6
|
import * as React from 'react';
|
|
6
7
|
|
|
7
8
|
import type { IAgent } from '../launcher/agents';
|
|
@@ -68,6 +69,7 @@ function renderIcon(icon?: LabIcon): React.ReactNode {
|
|
|
68
69
|
function OmniboxComponent(props: OmniboxWidget.IOptions): JSX.Element {
|
|
69
70
|
const {
|
|
70
71
|
commands,
|
|
72
|
+
paletteItems,
|
|
71
73
|
docRegistry,
|
|
72
74
|
agents,
|
|
73
75
|
placeholder,
|
|
@@ -103,13 +105,14 @@ function OmniboxComponent(props: OmniboxWidget.IOptions): JSX.Element {
|
|
|
103
105
|
computeSections({
|
|
104
106
|
query,
|
|
105
107
|
commands,
|
|
108
|
+
paletteItems,
|
|
106
109
|
docRegistry,
|
|
107
110
|
agents,
|
|
108
111
|
files,
|
|
109
112
|
recents,
|
|
110
113
|
trans
|
|
111
114
|
}),
|
|
112
|
-
[query, commands, docRegistry, agents, files, recents, trans]
|
|
115
|
+
[query, commands, paletteItems, docRegistry, agents, files, recents, trans]
|
|
113
116
|
);
|
|
114
117
|
const flat = React.useMemo(
|
|
115
118
|
() => [
|
|
@@ -334,6 +337,11 @@ export namespace OmniboxWidget {
|
|
|
334
337
|
*/
|
|
335
338
|
export interface IOptions {
|
|
336
339
|
commands: CommandRegistry;
|
|
340
|
+
/**
|
|
341
|
+
* Snapshot of the command palette's items, read once when the overlay
|
|
342
|
+
* opens; empty when the palette isn't available.
|
|
343
|
+
*/
|
|
344
|
+
paletteItems: ReadonlyArray<CommandPalette.IItem>;
|
|
337
345
|
docRegistry: DocumentRegistry;
|
|
338
346
|
/**
|
|
339
347
|
* Snapshot of the available agents, read once when the overlay opens.
|
package/src/svg.d.ts
ADDED
package/style/about.css
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* About dialog (xtralab:about). The header block is the dialog title, so it
|
|
3
|
+
* inherits the jp-Dialog-header type (size2/600 under chrome.css) — the
|
|
4
|
+
* wordmark scales up from there and the version line drops back to body
|
|
5
|
+
* size, weight and a muted color.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
.jp-xtralab-About-header {
|
|
9
|
+
display: flex;
|
|
10
|
+
align-items: center;
|
|
11
|
+
gap: 14px;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.jp-xtralab-About-logo {
|
|
15
|
+
flex-shrink: 0;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.jp-xtralab-About-header-info {
|
|
19
|
+
display: flex;
|
|
20
|
+
flex-direction: column;
|
|
21
|
+
align-items: flex-start;
|
|
22
|
+
gap: 2px;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.jp-xtralab-About-wordmark {
|
|
26
|
+
font-size: var(--jp-ui-font-size3);
|
|
27
|
+
font-weight: 700;
|
|
28
|
+
letter-spacing: -0.01em;
|
|
29
|
+
line-height: 1.2;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.jp-xtralab-About-version {
|
|
33
|
+
font-size: var(--jp-ui-font-size1);
|
|
34
|
+
font-weight: 400;
|
|
35
|
+
color: var(--jp-ui-font-color2);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.jp-xtralab-About-body {
|
|
39
|
+
display: flex;
|
|
40
|
+
flex-direction: column;
|
|
41
|
+
min-width: 360px;
|
|
42
|
+
font-size: var(--jp-ui-font-size1);
|
|
43
|
+
color: var(--jp-ui-font-color1);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.jp-xtralab-About-basedOn {
|
|
47
|
+
color: var(--jp-ui-font-color2);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.jp-xtralab-About-externalLinks {
|
|
51
|
+
padding-top: 12px;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
.jp-xtralab-About-externalLinks > a {
|
|
55
|
+
color: var(--jp-content-link-color);
|
|
56
|
+
text-decoration: none;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.jp-xtralab-About-externalLinks > a:hover {
|
|
60
|
+
text-decoration: underline;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
.jp-xtralab-About-copyright {
|
|
64
|
+
padding-top: 12px;
|
|
65
|
+
color: var(--jp-ui-font-color3);
|
|
66
|
+
}
|
package/style/index.css
CHANGED