@inflatable-cookie/longhorn 0.5.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/package.json +1 -7
- package/src/agent-control/generated/protocol.ts +228 -0
- package/src/agent-control/index.ts +1 -5
- package/src/agent-control/inject.ts +4 -1
- package/src/agent-control/selection.ts +42 -25
- package/src/agent-control/shim.ts +428 -198
- package/src/bridge/direct.ts +1 -1
- package/src/bridge/generated/fields.ts +4 -3
- package/src/bridge/generated/protocol.ts +62 -7
- package/src/bridge/generated/variant-fields.ts +1 -1
- package/src/bridge/job.ts +49 -12
- package/src/bridge/loopback.ts +7 -25
- package/src/bridge/operation.ts +13 -43
- package/src/bridge/router.ts +10 -23
- package/src/bridge/runtime/connection.ts +78 -109
- package/src/bridge/runtime/policy.ts +8 -28
- package/src/bridge/runtime/retry.ts +6 -18
- package/src/bridge/session.ts +4 -14
- package/src/bridge/stream/connection.ts +24 -55
- package/src/bridge/stream/source.ts +2 -6
- package/src/bridge/stream/tracker.ts +12 -12
- package/src/bridge/supervision.ts +104 -97
- package/src/bridge/validation/base.ts +21 -63
- package/src/bridge/validation/jobs.ts +11 -25
- package/src/bridge/validation/negotiation.ts +28 -43
- package/src/bridge/validation/operations.ts +29 -65
- package/src/bridge/validation/streams.ts +3 -10
- package/src/commands/client.ts +37 -28
- package/src/commands/controller.ts +119 -96
- package/src/commands/generated/fields.ts +7 -6
- package/src/commands/generated/protocol.ts +28 -1
- package/src/commands/generated/variant-fields.ts +1 -1
- package/src/commands/keyboard.ts +94 -100
- package/src/commands/physical-code.ts +11 -0
- package/src/commands/ports.ts +8 -13
- package/src/commands/projectors.ts +100 -75
- package/src/commands/validation.ts +434 -241
- package/src/config/client.ts +9 -22
- package/src/config/generated/base.ts +22 -6
- package/src/config/generated/fields.ts +4 -3
- package/src/config/generated/label-template.ts +1 -1
- package/src/config/generated/labels.ts +1 -1
- package/src/config/generated/protocol.ts +1 -1
- package/src/config/generated/restore.ts +35 -12
- package/src/config/generated/variant-fields.ts +1 -1
- package/src/config/names.ts +6 -12
- package/src/config/validation/commands.ts +11 -25
- package/src/config/validation/outcomes.ts +163 -70
- package/src/config/validation/primitives.ts +35 -80
- package/src/config/validation/projection.ts +100 -128
- package/src/core/connection.ts +187 -83
- package/src/core/controller-lifecycle.ts +144 -0
- package/src/core/generated/identifiers.ts +4 -0
- package/src/core/identifiers.ts +40 -0
- package/src/core/index.ts +10 -1
- package/src/core/json-value.ts +58 -0
- package/src/core/listeners.ts +35 -0
- package/src/core/record.ts +80 -0
- package/src/core/transport.ts +9 -11
- package/src/core/wire-copy.ts +7 -0
- package/src/history/client.ts +11 -13
- package/src/history/controller.ts +106 -108
- package/src/history/direct.ts +1 -3
- package/src/history/generated/fields.ts +4 -3
- package/src/history/generated/protocol.ts +8 -5
- package/src/history/generated/variant-fields.ts +1 -1
- package/src/history/ports.ts +7 -4
- package/src/history/serialized.ts +9 -13
- package/src/history/validation.ts +69 -75
- package/src/history-tree/client.ts +89 -11
- package/src/history-tree/controller.ts +380 -96
- package/src/history-tree/direct.ts +3 -1
- package/src/history-tree/generated/fields.ts +5 -3
- package/src/history-tree/generated/protocol.ts +43 -7
- package/src/history-tree/generated/variant-fields.ts +7 -1
- package/src/history-tree/ports.ts +12 -5
- package/src/history-tree/serialized.ts +39 -11
- package/src/history-tree/validation.ts +286 -78
- package/src/layout/generated/protocol.ts +4 -3
- package/src/layout/generated/variant-fields.ts +47 -0
- package/src/layout/index.ts +1 -1
- package/src/layout/ratio.ts +10 -9
- package/src/layout/validation.ts +98 -32
- package/src/layout/visibility.ts +1 -2
- package/src/licence/client.ts +48 -7
- package/src/licence/controller.ts +127 -70
- package/src/licence/direct.ts +3 -1
- package/src/licence/generated/fields.ts +4 -3
- package/src/licence/generated/key-conformance.json +28 -0
- package/src/licence/generated/protocol.ts +9 -5
- package/src/licence/generated/variant-fields.ts +1 -1
- package/src/licence/key.ts +42 -18
- package/src/licence/ports.ts +10 -3
- package/src/licence/serialized.ts +32 -9
- package/src/licence/validation.ts +134 -43
- package/src/native-content/client.ts +207 -234
- package/src/native-content/generated/fields.ts +6 -6
- package/src/native-content/generated/protocol.ts +16 -5
- package/src/native-content/generated/variant-fields.ts +1 -1
- package/src/native-content/ports.ts +11 -16
- package/src/native-content/serialized.ts +12 -19
- package/src/native-content/validation/base.ts +57 -80
- package/src/native-content/validation/messages.ts +24 -35
- package/src/native-content/validation/state.ts +31 -33
- package/src/notifications/client.ts +85 -51
- package/src/notifications/controller.ts +400 -145
- package/src/notifications/direct.ts +3 -1
- package/src/notifications/generated/fields.ts +4 -3
- package/src/notifications/generated/labels.ts +1 -1
- package/src/notifications/generated/protocol.ts +5 -1
- package/src/notifications/generated/variant-fields.ts +1 -1
- package/src/notifications/ports.ts +9 -4
- package/src/notifications/serialized.ts +11 -9
- package/src/notifications/tone.ts +1 -1
- package/src/notifications/validation.ts +165 -71
- package/src/operation/bridge.ts +187 -60
- package/src/operation/client.ts +48 -62
- package/src/operation/controller.ts +67 -97
- package/src/operation/direct.ts +1 -3
- package/src/operation/generated/fields.ts +4 -3
- package/src/operation/generated/labels.ts +1 -1
- package/src/operation/generated/protocol.ts +5 -1
- package/src/operation/generated/variant-fields.ts +1 -1
- package/src/operation/ports.ts +12 -10
- package/src/operation/serialized.ts +8 -9
- package/src/operation/validation.ts +189 -104
- package/src/settings/client.ts +11 -44
- package/src/settings/connection.ts +35 -53
- package/src/settings/generated/fields.ts +5 -4
- package/src/settings/generated/protocol.ts +14 -5
- package/src/settings/generated/variant-fields.ts +1 -1
- package/src/settings/names.ts +2 -4
- package/src/settings/registry.ts +23 -25
- package/src/settings/validation/authority.ts +21 -19
- package/src/settings/validation/command.ts +22 -41
- package/src/settings/validation/error.ts +2 -8
- package/src/settings/validation/primitives.ts +46 -97
- package/src/settings/validation/projection.ts +8 -24
- package/src/settings/validation/registry.ts +33 -79
- package/src/surface-transfer/client.ts +6 -18
- package/src/surface-transfer/generated/fields.ts +3 -3
- package/src/surface-transfer/generated/protocol.ts +3 -3
- package/src/surface-transfer/generated/variant-fields.ts +1 -1
- package/src/surface-transfer/validation.ts +91 -86
- package/src/surfaces/client.ts +33 -55
- package/src/surfaces/generated/fields.ts +3 -3
- package/src/surfaces/generated/protocol.ts +1 -1
- package/src/surfaces/generated/variant-fields.ts +1 -1
- package/src/surfaces/validation.ts +227 -99
- package/src/transfer/client.ts +26 -60
- package/src/transfer/connection.ts +29 -51
- package/src/transfer/generated/fields.ts +7 -6
- package/src/transfer/generated/protocol.ts +13 -5
- package/src/transfer/generated/variant-fields.ts +1 -1
- package/src/transfer/index.ts +8 -1
- package/src/transfer/payload.ts +20 -35
- package/src/transfer/validation.ts +169 -119
- package/src/update/client.ts +86 -9
- package/src/update/controller.ts +264 -116
- package/src/update/direct.ts +3 -1
- package/src/update/generated/fields.ts +5 -4
- package/src/update/generated/protocol.ts +25 -9
- package/src/update/generated/variant-fields.ts +4 -2
- package/src/update/ports.ts +14 -6
- package/src/update/serialized.ts +36 -10
- package/src/update/validation.ts +118 -48
package/src/commands/keyboard.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { COMMAND_MAXIMUM_PHYSICAL_CODE_BYTES } from "./generated/protocol.ts";
|
|
2
1
|
import type {
|
|
3
2
|
CommandBindingCandidate,
|
|
4
3
|
CommandDiscoveryRecord,
|
|
@@ -11,11 +10,9 @@ import type {
|
|
|
11
10
|
CommandKeymapConflict,
|
|
12
11
|
CommandPlatform,
|
|
13
12
|
} from "./generated/protocol.ts";
|
|
13
|
+
import { isPhysicalCode } from "./physical-code.ts";
|
|
14
14
|
import { shortcutLabel } from "./projectors.ts";
|
|
15
|
-
import type {
|
|
16
|
-
CommandExecutionOutcome,
|
|
17
|
-
CommandExecutionSource,
|
|
18
|
-
} from "./ports.ts";
|
|
15
|
+
import type { CommandExecutionOutcome, CommandExecutionSource } from "./ports.ts";
|
|
19
16
|
|
|
20
17
|
export interface KeyboardEventLike {
|
|
21
18
|
readonly code: string;
|
|
@@ -33,11 +30,11 @@ export interface KeyboardEventLike {
|
|
|
33
30
|
export interface CommandKeyboardResolutionOptions {
|
|
34
31
|
readonly platform: CommandPlatform;
|
|
35
32
|
readonly input: CommandKeyboardInput;
|
|
36
|
-
readonly contextPath:
|
|
33
|
+
readonly contextPath: ReadonlyArray<string>;
|
|
37
34
|
readonly mode: CommandKeyboardMode;
|
|
38
|
-
readonly bindings:
|
|
39
|
-
readonly commands:
|
|
40
|
-
readonly reserved?: (platform: CommandPlatform, chord: CommandKeyChord) => boolean;
|
|
35
|
+
readonly bindings: ReadonlyArray<CommandEffectiveBinding>;
|
|
36
|
+
readonly commands: ReadonlyArray<CommandDiscoveryRecord>;
|
|
37
|
+
readonly reserved?: ((platform: CommandPlatform, chord: CommandKeyChord) => boolean) | undefined;
|
|
41
38
|
}
|
|
42
39
|
|
|
43
40
|
export interface CommandKeyboardDispatch {
|
|
@@ -47,8 +44,7 @@ export interface CommandKeyboardDispatch {
|
|
|
47
44
|
): Promise<CommandExecutionOutcome>;
|
|
48
45
|
}
|
|
49
46
|
|
|
50
|
-
export interface RouteKeyboardEventOptions
|
|
51
|
-
extends Omit<CommandKeyboardResolutionOptions, "input"> {
|
|
47
|
+
export interface RouteKeyboardEventOptions extends Omit<CommandKeyboardResolutionOptions, "input"> {
|
|
52
48
|
readonly dispatcher: CommandKeyboardDispatch;
|
|
53
49
|
readonly editableTarget?: (target: unknown) => boolean;
|
|
54
50
|
readonly onCapture?: (chord: CommandKeyChord, label: string) => void;
|
|
@@ -84,9 +80,15 @@ export function resolveCommandKeyboard(
|
|
|
84
80
|
options: CommandKeyboardResolutionOptions,
|
|
85
81
|
): CommandKeyResolution {
|
|
86
82
|
const { input } = options;
|
|
87
|
-
if (!
|
|
88
|
-
|
|
89
|
-
|
|
83
|
+
if (!isPhysicalCode(input.chord.code)) {
|
|
84
|
+
return { kind: "unbound" };
|
|
85
|
+
}
|
|
86
|
+
if (input.repeat) {
|
|
87
|
+
return gated("repeat");
|
|
88
|
+
}
|
|
89
|
+
if (input.composing) {
|
|
90
|
+
return gated("composition");
|
|
91
|
+
}
|
|
90
92
|
if (options.reserved?.(options.platform, input.chord) === true) {
|
|
91
93
|
return gated("reserved");
|
|
92
94
|
}
|
|
@@ -98,9 +100,7 @@ export function resolveCommandKeyboard(
|
|
|
98
100
|
};
|
|
99
101
|
}
|
|
100
102
|
|
|
101
|
-
const positions = new Map(
|
|
102
|
-
options.contextPath.map((contextId, index) => [contextId, index]),
|
|
103
|
-
);
|
|
103
|
+
const positions = new Map(options.contextPath.map((contextId, index) => [contextId, index]));
|
|
104
104
|
const matches = options.bindings
|
|
105
105
|
.flatMap((binding) => {
|
|
106
106
|
const specificity = positions.get(binding.contextId);
|
|
@@ -115,38 +115,34 @@ export function resolveCommandKeyboard(
|
|
|
115
115
|
})
|
|
116
116
|
.sort(
|
|
117
117
|
(left, right) =>
|
|
118
|
-
right.specificity - left.specificity ||
|
|
119
|
-
left.binding.id.localeCompare(right.binding.id),
|
|
118
|
+
right.specificity - left.specificity || compareText(left.binding.id, right.binding.id),
|
|
120
119
|
);
|
|
121
|
-
|
|
120
|
+
const [firstMatch] = matches;
|
|
121
|
+
if (firstMatch === undefined) {
|
|
122
|
+
return { kind: "unbound" };
|
|
123
|
+
}
|
|
122
124
|
|
|
123
|
-
const winningSpecificity =
|
|
124
|
-
const winningContext =
|
|
125
|
-
const winning = matches.filter(
|
|
126
|
-
|
|
127
|
-
);
|
|
128
|
-
const distinctInvocations = uniqueInvocations(
|
|
129
|
-
winning.map(({ binding }) => binding.invocation),
|
|
130
|
-
);
|
|
125
|
+
const winningSpecificity = firstMatch.specificity;
|
|
126
|
+
const winningContext = firstMatch.binding.contextId;
|
|
127
|
+
const winning = matches.filter(({ specificity }) => specificity === winningSpecificity);
|
|
128
|
+
const distinctInvocations = uniqueInvocations(winning.map(({ binding }) => binding.invocation));
|
|
131
129
|
const conflict = distinctInvocations.length > 1;
|
|
132
|
-
const representativeId =
|
|
133
|
-
const candidates: CommandBindingCandidate
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
: conflict
|
|
144
|
-
|
|
145
|
-
:
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
}),
|
|
149
|
-
);
|
|
130
|
+
const representativeId = firstMatch.binding.id;
|
|
131
|
+
const candidates: Array<CommandBindingCandidate> = matches.map(({ binding, specificity }) => ({
|
|
132
|
+
bindingId: binding.id,
|
|
133
|
+
source: binding.source,
|
|
134
|
+
matchedContextId: binding.contextId,
|
|
135
|
+
specificity,
|
|
136
|
+
invocation: binding.invocation,
|
|
137
|
+
disposition:
|
|
138
|
+
specificity < winningSpecificity
|
|
139
|
+
? { kind: "shadowed", byContextId: winningContext }
|
|
140
|
+
: conflict
|
|
141
|
+
? { kind: "conflict" }
|
|
142
|
+
: binding.id === representativeId
|
|
143
|
+
? { kind: "winner" }
|
|
144
|
+
: { kind: "equivalent" },
|
|
145
|
+
}));
|
|
150
146
|
|
|
151
147
|
if (conflict) {
|
|
152
148
|
const record: CommandKeymapConflict = {
|
|
@@ -159,10 +155,8 @@ export function resolveCommandKeyboard(
|
|
|
159
155
|
return { kind: "conflict", conflict: record, candidates };
|
|
160
156
|
}
|
|
161
157
|
|
|
162
|
-
const binding =
|
|
163
|
-
const declaration = options.commands.find(
|
|
164
|
-
({ id }) => id === binding.invocation.commandId,
|
|
165
|
-
);
|
|
158
|
+
const binding = firstMatch.binding;
|
|
159
|
+
const declaration = options.commands.find(({ id }) => id === binding.invocation.commandId);
|
|
166
160
|
if (input.editableText && declaration?.textInputPolicy === "blocked") {
|
|
167
161
|
return { kind: "gated", gate: "textInput", candidates };
|
|
168
162
|
}
|
|
@@ -185,8 +179,7 @@ export function routeCommandKeyboardEvent(
|
|
|
185
179
|
...options,
|
|
186
180
|
input: normalizeKeyboardEvent(event, options.editableTarget),
|
|
187
181
|
});
|
|
188
|
-
const consumed =
|
|
189
|
-
resolution.kind === "captured" || resolution.kind === "resolved";
|
|
182
|
+
const consumed = resolution.kind === "captured" || resolution.kind === "resolved";
|
|
190
183
|
if (consumed) {
|
|
191
184
|
event.preventDefault();
|
|
192
185
|
event.stopPropagation();
|
|
@@ -199,27 +192,29 @@ export function routeCommandKeyboardEvent(
|
|
|
199
192
|
return {
|
|
200
193
|
consumed,
|
|
201
194
|
resolution,
|
|
202
|
-
execution: options.dispatcher.dispatchInvocation(
|
|
203
|
-
resolution.winner.invocation,
|
|
204
|
-
"keyboard",
|
|
205
|
-
),
|
|
195
|
+
execution: options.dispatcher.dispatchInvocation(resolution.winner.invocation, "keyboard"),
|
|
206
196
|
};
|
|
207
197
|
}
|
|
208
198
|
return { consumed, resolution };
|
|
209
199
|
}
|
|
210
200
|
|
|
211
201
|
export function isEditableCommandTarget(target: unknown): boolean {
|
|
212
|
-
if (typeof target !== "object" || target === null)
|
|
202
|
+
if (typeof target !== "object" || target === null) {
|
|
203
|
+
return false;
|
|
204
|
+
}
|
|
213
205
|
const record = target as {
|
|
214
206
|
readonly isContentEditable?: boolean;
|
|
215
207
|
readonly tagName?: unknown;
|
|
216
208
|
readonly role?: unknown;
|
|
217
209
|
getAttribute?(name: string): string | null;
|
|
218
210
|
};
|
|
219
|
-
if (record.isContentEditable === true)
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
211
|
+
if (record.isContentEditable === true) {
|
|
212
|
+
return true;
|
|
213
|
+
}
|
|
214
|
+
const tag = typeof record.tagName === "string" ? record.tagName.toLowerCase() : "";
|
|
215
|
+
if (tag === "input" || tag === "textarea" || tag === "select") {
|
|
216
|
+
return true;
|
|
217
|
+
}
|
|
223
218
|
const role =
|
|
224
219
|
typeof record.getAttribute === "function"
|
|
225
220
|
? record.getAttribute("role")
|
|
@@ -229,9 +224,7 @@ export function isEditableCommandTarget(target: unknown): boolean {
|
|
|
229
224
|
return role === "textbox" || role === "searchbox";
|
|
230
225
|
}
|
|
231
226
|
|
|
232
|
-
function gated(
|
|
233
|
-
gate: "repeat" | "composition" | "reserved",
|
|
234
|
-
): CommandKeyResolution {
|
|
227
|
+
function gated(gate: "repeat" | "composition" | "reserved"): CommandKeyResolution {
|
|
235
228
|
return { kind: "gated", gate, candidates: [] };
|
|
236
229
|
}
|
|
237
230
|
|
|
@@ -251,8 +244,7 @@ function resolveBindingChord(
|
|
|
251
244
|
modifiers: {
|
|
252
245
|
control:
|
|
253
246
|
binding.trigger.modifiers.control ||
|
|
254
|
-
(binding.trigger.modifiers.primary &&
|
|
255
|
-
(platform === "windows" || platform === "linux")),
|
|
247
|
+
(binding.trigger.modifiers.primary && (platform === "windows" || platform === "linux")),
|
|
256
248
|
alt: binding.trigger.modifiers.alt,
|
|
257
249
|
shift: binding.trigger.modifiers.shift,
|
|
258
250
|
meta:
|
|
@@ -273,8 +265,8 @@ function sameChord(left: CommandKeyChord, right: CommandKeyChord): boolean {
|
|
|
273
265
|
}
|
|
274
266
|
|
|
275
267
|
function uniqueInvocations(
|
|
276
|
-
invocations:
|
|
277
|
-
): CommandInvocation
|
|
268
|
+
invocations: ReadonlyArray<CommandInvocation>,
|
|
269
|
+
): Array<CommandInvocation> {
|
|
278
270
|
const keyed = new Map<string, CommandInvocation>();
|
|
279
271
|
for (const invocation of invocations) {
|
|
280
272
|
keyed.set(invocationKey(invocation), invocation);
|
|
@@ -284,31 +276,35 @@ function uniqueInvocations(
|
|
|
284
276
|
|
|
285
277
|
function invocationKey(invocation: CommandInvocation): string {
|
|
286
278
|
const argumentsKey = Object.entries(invocation.arguments)
|
|
287
|
-
.sort(([left], [right]) => left
|
|
279
|
+
.sort(([left], [right]) => compareText(left, right))
|
|
288
280
|
.map(([key, value]) => [key, value]);
|
|
289
281
|
return JSON.stringify([invocation.commandId, argumentsKey]);
|
|
290
282
|
}
|
|
291
283
|
|
|
292
|
-
function compareInvocation(
|
|
293
|
-
left: CommandInvocation,
|
|
294
|
-
right: CommandInvocation,
|
|
295
|
-
): number {
|
|
284
|
+
function compareInvocation(left: CommandInvocation, right: CommandInvocation): number {
|
|
296
285
|
const id = compareText(left.commandId, right.commandId);
|
|
297
|
-
if (id !== 0)
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
);
|
|
301
|
-
const rightArguments = Object.entries(right.arguments).sort(([a], [b]) =>
|
|
302
|
-
compareText(a, b),
|
|
303
|
-
);
|
|
286
|
+
if (id !== 0) {
|
|
287
|
+
return id;
|
|
288
|
+
}
|
|
289
|
+
const leftArguments = Object.entries(left.arguments).sort(([a], [b]) => compareText(a, b));
|
|
290
|
+
const rightArguments = Object.entries(right.arguments).sort(([a], [b]) => compareText(a, b));
|
|
304
291
|
const length = Math.min(leftArguments.length, rightArguments.length);
|
|
305
292
|
for (let index = 0; index < length; index += 1) {
|
|
306
|
-
const
|
|
307
|
-
const
|
|
293
|
+
const leftArgument = leftArguments[index];
|
|
294
|
+
const rightArgument = rightArguments[index];
|
|
295
|
+
if (leftArgument === undefined || rightArgument === undefined) {
|
|
296
|
+
break;
|
|
297
|
+
}
|
|
298
|
+
const [leftId, leftValue] = leftArgument;
|
|
299
|
+
const [rightId, rightValue] = rightArgument;
|
|
308
300
|
const field = compareText(leftId, rightId);
|
|
309
|
-
if (field !== 0)
|
|
301
|
+
if (field !== 0) {
|
|
302
|
+
return field;
|
|
303
|
+
}
|
|
310
304
|
const value = compareArgumentValue(leftValue, rightValue);
|
|
311
|
-
if (value !== 0)
|
|
305
|
+
if (value !== 0) {
|
|
306
|
+
return value;
|
|
307
|
+
}
|
|
312
308
|
}
|
|
313
309
|
return leftArguments.length - rightArguments.length;
|
|
314
310
|
}
|
|
@@ -325,7 +321,9 @@ function compareArgumentValue(
|
|
|
325
321
|
enum: 4,
|
|
326
322
|
} as const;
|
|
327
323
|
const rank = ranks[left.kind] - ranks[right.kind];
|
|
328
|
-
if (rank !== 0)
|
|
324
|
+
if (rank !== 0) {
|
|
325
|
+
return rank;
|
|
326
|
+
}
|
|
329
327
|
if (
|
|
330
328
|
(left.kind === "number" || left.kind === "integer") &&
|
|
331
329
|
(right.kind === "number" || right.kind === "integer")
|
|
@@ -339,23 +337,19 @@ function compareArgumentValue(
|
|
|
339
337
|
}
|
|
340
338
|
|
|
341
339
|
function compareText(left: string, right: string): number {
|
|
342
|
-
const leftValues =
|
|
343
|
-
const rightValues =
|
|
340
|
+
const leftValues = Array.from(left);
|
|
341
|
+
const rightValues = Array.from(right);
|
|
344
342
|
const length = Math.min(leftValues.length, rightValues.length);
|
|
345
343
|
for (let index = 0; index < length; index += 1) {
|
|
346
|
-
const
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
344
|
+
const leftCode = leftValues[index]?.codePointAt(0);
|
|
345
|
+
const rightCode = rightValues[index]?.codePointAt(0);
|
|
346
|
+
if (leftCode === undefined || rightCode === undefined) {
|
|
347
|
+
break;
|
|
348
|
+
}
|
|
349
|
+
const difference = leftCode - rightCode;
|
|
350
|
+
if (difference !== 0) {
|
|
351
|
+
return difference;
|
|
352
|
+
}
|
|
350
353
|
}
|
|
351
354
|
return leftValues.length - rightValues.length;
|
|
352
355
|
}
|
|
353
|
-
|
|
354
|
-
function validPhysicalCode(code: string): boolean {
|
|
355
|
-
return (
|
|
356
|
-
code !== "Unidentified" &&
|
|
357
|
-
code.length > 0 &&
|
|
358
|
-
code.length <= COMMAND_MAXIMUM_PHYSICAL_CODE_BYTES &&
|
|
359
|
-
/^[A-Z][A-Za-z0-9]*$/u.test(code)
|
|
360
|
-
);
|
|
361
|
-
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { COMMAND_MAXIMUM_PHYSICAL_CODE_BYTES } from "./generated/protocol.ts";
|
|
2
|
+
|
|
3
|
+
/** Whether Rust's `CommandPhysicalCode` would admit `value`. */
|
|
4
|
+
export function isPhysicalCode(value: unknown): value is string {
|
|
5
|
+
return (
|
|
6
|
+
typeof value === "string" &&
|
|
7
|
+
value !== "Unidentified" &&
|
|
8
|
+
value.length <= COMMAND_MAXIMUM_PHYSICAL_CODE_BYTES &&
|
|
9
|
+
/^[A-Z][A-Za-z0-9]*$/u.test(value)
|
|
10
|
+
);
|
|
11
|
+
}
|
package/src/commands/ports.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Unlisten } from "../core/transport.ts";
|
|
1
2
|
import type {
|
|
2
3
|
CommandArguments,
|
|
3
4
|
CommandAvailabilitySnapshot,
|
|
@@ -12,32 +13,26 @@ import type {
|
|
|
12
13
|
CommandRequestId,
|
|
13
14
|
} from "./generated/protocol.ts";
|
|
14
15
|
|
|
15
|
-
export type CommandUnlisten =
|
|
16
|
+
export type CommandUnlisten = Unlisten;
|
|
16
17
|
|
|
17
18
|
export interface CommandSnapshotPort<Snapshot> {
|
|
18
19
|
load(): Promise<Snapshot>;
|
|
19
20
|
listen?(invalidate: () => void): CommandUnlisten | Promise<CommandUnlisten>;
|
|
20
21
|
}
|
|
21
22
|
|
|
22
|
-
|
|
23
|
-
|
|
23
|
+
// oxlint-disable-next-line typescript/no-empty-object-type -- This public interface permits consumer declaration merging.
|
|
24
|
+
export interface CommandCataloguePort extends CommandSnapshotPort<CommandCatalogueSnapshot> {}
|
|
24
25
|
|
|
25
|
-
export interface CommandKeymapPort
|
|
26
|
-
extends CommandSnapshotPort<CommandKeymapLoadOutcome> {
|
|
26
|
+
export interface CommandKeymapPort extends CommandSnapshotPort<CommandKeymapLoadOutcome> {
|
|
27
27
|
preview?(request: CommandKeymapPreview): Promise<CommandKeymapPreviewResult>;
|
|
28
28
|
commit?(request: CommandKeymapCommit): Promise<CommandKeymapMutationResult>;
|
|
29
29
|
reset?(request: CommandKeymapReset): Promise<CommandKeymapMutationResult>;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
// oxlint-disable-next-line typescript/no-empty-object-type -- This public interface permits consumer declaration merging.
|
|
33
|
+
export interface CommandAvailabilityPort extends CommandSnapshotPort<CommandAvailabilitySnapshot> {}
|
|
34
34
|
|
|
35
|
-
export type CommandExecutionSource =
|
|
36
|
-
| "palette"
|
|
37
|
-
| "keyboard"
|
|
38
|
-
| "menu"
|
|
39
|
-
| "help"
|
|
40
|
-
| "consumer";
|
|
35
|
+
export type CommandExecutionSource = "palette" | "keyboard" | "menu" | "help" | "consumer";
|
|
41
36
|
|
|
42
37
|
export interface CommandExecutionIntent {
|
|
43
38
|
readonly requestId: CommandRequestId;
|
|
@@ -23,32 +23,27 @@ export interface CommandProjectionRecord {
|
|
|
23
23
|
readonly id: CommandId;
|
|
24
24
|
readonly label: string;
|
|
25
25
|
readonly description: string | null;
|
|
26
|
-
readonly categoryPath:
|
|
27
|
-
readonly keywords:
|
|
26
|
+
readonly categoryPath: ReadonlyArray<string>;
|
|
27
|
+
readonly keywords: ReadonlyArray<string>;
|
|
28
28
|
readonly icon: string | null;
|
|
29
29
|
readonly availability: CommandAvailability;
|
|
30
|
-
readonly shortcuts:
|
|
30
|
+
readonly shortcuts: ReadonlyArray<CommandShortcutRecord>;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
export interface CommandSettingsRecord extends CommandProjectionRecord {
|
|
34
|
-
readonly bindings:
|
|
34
|
+
readonly bindings: ReadonlyArray<CommandEffectiveBinding>;
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
export interface CommandSurfaceProjection {
|
|
38
|
-
readonly palette:
|
|
39
|
-
readonly menu:
|
|
40
|
-
readonly help:
|
|
41
|
-
readonly settings:
|
|
42
|
-
readonly shortcuts:
|
|
43
|
-
readonly reverseLookup: ReadonlyMap<CommandId,
|
|
44
|
-
readonly conflicts:
|
|
38
|
+
readonly palette: ReadonlyArray<CommandProjectionRecord>;
|
|
39
|
+
readonly menu: ReadonlyArray<CommandProjectionRecord>;
|
|
40
|
+
readonly help: ReadonlyArray<CommandProjectionRecord>;
|
|
41
|
+
readonly settings: ReadonlyArray<CommandSettingsRecord>;
|
|
42
|
+
readonly shortcuts: ReadonlyArray<CommandShortcutRecord>;
|
|
43
|
+
readonly reverseLookup: ReadonlyMap<CommandId, ReadonlyArray<CommandShortcutRecord>>;
|
|
44
|
+
readonly conflicts: ReadonlyArray<CommandKeymapConflict>;
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
const AVAILABLE: CommandAvailability = {
|
|
48
|
-
state: "available",
|
|
49
|
-
reason: null,
|
|
50
|
-
};
|
|
51
|
-
|
|
52
47
|
export function joinCommandState(
|
|
53
48
|
catalogue: CommandCatalogueSnapshot,
|
|
54
49
|
keymap: CommandKeymapSnapshot,
|
|
@@ -63,9 +58,7 @@ export function joinCommandState(
|
|
|
63
58
|
);
|
|
64
59
|
}
|
|
65
60
|
if (keymap.registryDigest !== catalogue.registryDigest) {
|
|
66
|
-
throw new CommandProjectionConsistencyError(
|
|
67
|
-
"catalogue and keymap registry digests differ",
|
|
68
|
-
);
|
|
61
|
+
throw new CommandProjectionConsistencyError("catalogue and keymap registry digests differ");
|
|
69
62
|
}
|
|
70
63
|
const known = new Set(catalogue.commands.map(({ id }) => id));
|
|
71
64
|
const records = new Set<string>();
|
|
@@ -90,48 +83,51 @@ export function projectCommandSurfaces(
|
|
|
90
83
|
platform: CommandPlatform,
|
|
91
84
|
): CommandSurfaceProjection {
|
|
92
85
|
const availability = new Map(
|
|
93
|
-
state.availability.records.map((record) => [
|
|
94
|
-
record.commandId,
|
|
95
|
-
record.availability,
|
|
96
|
-
]),
|
|
86
|
+
state.availability.records.map((record) => [record.commandId, record.availability]),
|
|
97
87
|
);
|
|
98
|
-
const reverseLookup = new Map<CommandId,
|
|
99
|
-
const shortcuts: CommandShortcutRecord
|
|
100
|
-
|
|
101
|
-
const
|
|
102
|
-
|
|
88
|
+
const reverseLookup = new Map<CommandId, ReadonlyArray<CommandShortcutRecord>>();
|
|
89
|
+
const shortcuts: Array<CommandShortcutRecord> = [];
|
|
90
|
+
const rows = state.catalogue.commands.map((command) => {
|
|
91
|
+
const { id, label, description, categoryPath, keywords, icon, visibility } = command;
|
|
92
|
+
const value = availability.get(id);
|
|
93
|
+
if (value === undefined) {
|
|
94
|
+
throw new CommandProjectionConsistencyError(`availability is missing command ${id}`);
|
|
95
|
+
}
|
|
96
|
+
const records = shortcutsForCommand(state.keymap, id, platform);
|
|
97
|
+
reverseLookup.set(id, records);
|
|
103
98
|
shortcuts.push(...records);
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
99
|
+
return {
|
|
100
|
+
record: {
|
|
101
|
+
id,
|
|
102
|
+
label,
|
|
103
|
+
description,
|
|
104
|
+
categoryPath,
|
|
105
|
+
keywords,
|
|
106
|
+
icon,
|
|
107
|
+
availability: value,
|
|
108
|
+
shortcuts: records,
|
|
109
|
+
},
|
|
110
|
+
visibility,
|
|
111
|
+
};
|
|
114
112
|
});
|
|
115
|
-
const visible =
|
|
116
|
-
({ visibility }) => !visibility.hidden,
|
|
117
|
-
);
|
|
113
|
+
const visible = rows.filter(({ visibility }) => !visibility.hidden);
|
|
118
114
|
return {
|
|
119
115
|
palette: visible
|
|
120
116
|
.filter(({ visibility }) => visibility.palette)
|
|
121
|
-
.map(
|
|
117
|
+
.map(({ record }) => record)
|
|
122
118
|
.filter(({ availability }) => availability.state !== "hidden"),
|
|
123
119
|
menu: visible
|
|
124
120
|
.filter(({ visibility }) => visibility.menu)
|
|
125
|
-
.map(
|
|
121
|
+
.map(({ record }) => record)
|
|
126
122
|
.filter(({ availability }) => availability.state !== "hidden"),
|
|
127
123
|
help: visible
|
|
128
124
|
.filter(({ visibility }) => visibility.help)
|
|
129
|
-
.map(
|
|
125
|
+
.map(({ record }) => record)
|
|
130
126
|
.filter(({ availability }) => availability.state !== "hidden"),
|
|
131
127
|
settings: visible
|
|
132
128
|
.filter(({ visibility }) => visibility.settings)
|
|
133
|
-
.map((record) => ({
|
|
134
|
-
...
|
|
129
|
+
.map(({ record }) => ({
|
|
130
|
+
...record,
|
|
135
131
|
bindings: state.keymap.bindings.filter(
|
|
136
132
|
({ invocation }) => invocation.commandId === record.id,
|
|
137
133
|
),
|
|
@@ -143,10 +139,35 @@ export function projectCommandSurfaces(
|
|
|
143
139
|
}
|
|
144
140
|
|
|
145
141
|
export function searchCommands(
|
|
146
|
-
records:
|
|
142
|
+
records: ReadonlyArray<CommandDiscoveryRecord>,
|
|
147
143
|
query: string,
|
|
148
|
-
):
|
|
149
|
-
|
|
144
|
+
): ReadonlyArray<CommandSearchHit> {
|
|
145
|
+
return searchCommandRecords(records, query);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export function searchCommandSettings(
|
|
149
|
+
records: ReadonlyArray<CommandSettingsRecord>,
|
|
150
|
+
query: string,
|
|
151
|
+
): ReadonlyArray<CommandSettingsRecord> {
|
|
152
|
+
if (query.trim().length === 0) {
|
|
153
|
+
return records;
|
|
154
|
+
}
|
|
155
|
+
return searchCommandRecords(records, query).map(({ record }) => record);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
type SearchableCommand = Pick<
|
|
159
|
+
CommandProjectionRecord,
|
|
160
|
+
"id" | "label" | "description" | "categoryPath" | "keywords"
|
|
161
|
+
>;
|
|
162
|
+
|
|
163
|
+
function searchCommandRecords<Record extends SearchableCommand>(
|
|
164
|
+
records: ReadonlyArray<Record>,
|
|
165
|
+
query: string,
|
|
166
|
+
): ReadonlyArray<{ record: Record; score: number }> {
|
|
167
|
+
const terms = query
|
|
168
|
+
.split(/\s+/u)
|
|
169
|
+
.filter(Boolean)
|
|
170
|
+
.map((term) => term.toLowerCase());
|
|
150
171
|
return records
|
|
151
172
|
.flatMap((record) => {
|
|
152
173
|
const score = scoreRecord(record, terms);
|
|
@@ -155,10 +176,7 @@ export function searchCommands(
|
|
|
155
176
|
.sort(
|
|
156
177
|
(left, right) =>
|
|
157
178
|
left.score - right.score ||
|
|
158
|
-
compareUnicodeScalars(
|
|
159
|
-
left.record.label.toLowerCase(),
|
|
160
|
-
right.record.label.toLowerCase(),
|
|
161
|
-
) ||
|
|
179
|
+
compareUnicodeScalars(left.record.label.toLowerCase(), right.record.label.toLowerCase()) ||
|
|
162
180
|
compareUnicodeScalars(left.record.id, right.record.id),
|
|
163
181
|
);
|
|
164
182
|
}
|
|
@@ -167,12 +185,11 @@ export function shortcutsForCommand(
|
|
|
167
185
|
keymap: CommandKeymapSnapshot,
|
|
168
186
|
commandId: CommandId,
|
|
169
187
|
platform: CommandPlatform,
|
|
170
|
-
):
|
|
188
|
+
): ReadonlyArray<CommandShortcutRecord> {
|
|
171
189
|
return keymap.bindings
|
|
172
190
|
.filter(
|
|
173
191
|
(binding) =>
|
|
174
|
-
binding.invocation.commandId === commandId &&
|
|
175
|
-
includesPlatform(binding.platform, platform),
|
|
192
|
+
binding.invocation.commandId === commandId && includesPlatform(binding.platform, platform),
|
|
176
193
|
)
|
|
177
194
|
.map((binding) => {
|
|
178
195
|
const chord = resolveTrigger(binding, platform);
|
|
@@ -186,10 +203,7 @@ export function shortcutsForCommand(
|
|
|
186
203
|
});
|
|
187
204
|
}
|
|
188
205
|
|
|
189
|
-
export function shortcutLabel(
|
|
190
|
-
chord: CommandKeyChord,
|
|
191
|
-
platform: CommandPlatform,
|
|
192
|
-
): string {
|
|
206
|
+
export function shortcutLabel(chord: CommandKeyChord, platform: CommandPlatform): string {
|
|
193
207
|
const key = keyLabel(chord.code);
|
|
194
208
|
if (platform === "macOs") {
|
|
195
209
|
return [
|
|
@@ -218,11 +232,11 @@ export class CommandProjectionConsistencyError extends Error {
|
|
|
218
232
|
}
|
|
219
233
|
}
|
|
220
234
|
|
|
221
|
-
function scoreRecord(
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
235
|
+
function scoreRecord(record: SearchableCommand, terms: ReadonlyArray<string>): number | undefined {
|
|
236
|
+
if (terms.length === 0) {
|
|
237
|
+
return 0;
|
|
238
|
+
}
|
|
239
|
+
const id = record.id.toLowerCase();
|
|
226
240
|
const label = record.label.toLowerCase();
|
|
227
241
|
const description = record.description?.toLowerCase() ?? "";
|
|
228
242
|
const keywords = record.keywords.map((keyword) => keyword.toLowerCase());
|
|
@@ -243,13 +257,15 @@ function scoreRecord(
|
|
|
243
257
|
? 50
|
|
244
258
|
: record.categoryPath.some((category) => category.includes(term))
|
|
245
259
|
? 60
|
|
246
|
-
:
|
|
260
|
+
: id.includes(term)
|
|
247
261
|
? 70
|
|
248
262
|
: description.includes(term)
|
|
249
263
|
? 80
|
|
250
264
|
: undefined;
|
|
251
|
-
if (termScore === undefined)
|
|
252
|
-
|
|
265
|
+
if (termScore === undefined) {
|
|
266
|
+
return undefined;
|
|
267
|
+
}
|
|
268
|
+
score = Math.min(0xff_ff_ff_ff, score + termScore);
|
|
253
269
|
}
|
|
254
270
|
return score;
|
|
255
271
|
}
|
|
@@ -280,8 +296,12 @@ function resolveTrigger(
|
|
|
280
296
|
}
|
|
281
297
|
|
|
282
298
|
function keyLabel(code: string): string {
|
|
283
|
-
if (code.length === 4 && code.startsWith("Key"))
|
|
284
|
-
|
|
299
|
+
if (code.length === 4 && code.startsWith("Key")) {
|
|
300
|
+
return code.slice(3);
|
|
301
|
+
}
|
|
302
|
+
if (code.length === 6 && code.startsWith("Digit")) {
|
|
303
|
+
return code.slice(5);
|
|
304
|
+
}
|
|
285
305
|
return (
|
|
286
306
|
{
|
|
287
307
|
ArrowUp: "↑",
|
|
@@ -294,13 +314,18 @@ function keyLabel(code: string): string {
|
|
|
294
314
|
}
|
|
295
315
|
|
|
296
316
|
function compareUnicodeScalars(left: string, right: string): number {
|
|
297
|
-
const leftValues =
|
|
298
|
-
const rightValues =
|
|
317
|
+
const leftValues = Array.from(left);
|
|
318
|
+
const rightValues = Array.from(right);
|
|
299
319
|
const length = Math.min(leftValues.length, rightValues.length);
|
|
300
320
|
for (let index = 0; index < length; index += 1) {
|
|
301
|
-
const leftCode = leftValues[index]
|
|
302
|
-
const rightCode = rightValues[index]
|
|
303
|
-
if (leftCode
|
|
321
|
+
const leftCode = leftValues[index]?.codePointAt(0);
|
|
322
|
+
const rightCode = rightValues[index]?.codePointAt(0);
|
|
323
|
+
if (leftCode === undefined || rightCode === undefined) {
|
|
324
|
+
break;
|
|
325
|
+
}
|
|
326
|
+
if (leftCode !== rightCode) {
|
|
327
|
+
return leftCode - rightCode;
|
|
328
|
+
}
|
|
304
329
|
}
|
|
305
330
|
return leftValues.length - rightValues.length;
|
|
306
331
|
}
|