Repository navigation
Expand file tree
/
Copy pathReferenceEntry.tsx
More file actions
114 lines (103 loc) · 2.85 KB
/
Copy pathReferenceEntry.tsx
File metadata and controls
114 lines (103 loc) · 2.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import React, { Fragment } from "react";
import {
actionReferences,
modifierReferences,
scopeReferences,
} from "@cursorless/lib-common";
import type { ReferenceEntry } from "@cursorless/lib-common";
export function ActionReference({ id }: { id: keyof typeof actionReferences }) {
return <ReferenceEntryComponent id={id} entry={actionReferences[id]} />;
}
export function ModifierReference({
id,
}: {
id: keyof typeof modifierReferences;
}) {
return <ReferenceEntryComponent id={id} entry={modifierReferences[id]} />;
}
export function ScopeReference({ id }: { id: keyof typeof scopeReferences }) {
return <ReferenceEntryComponent id={id} entry={scopeReferences[id]} />;
}
function ReferenceEntryComponent({
id,
entry,
}: {
id: string;
entry: ReferenceEntry;
}) {
return (
<>
{entry.description != null && <p>{entry.description}</p>}
<p>
Cursorless ID: <code>{id}</code>
</p>
{entry.defaultSpokenForm != null && (
<div className="mb-3">
<div>
Default spoken form: <code>{entry.defaultSpokenForm}</code>
</div>
{entry.legacySpokenForms != null && (
<div>
Legacy spoken forms:{" "}
{entry.legacySpokenForms.map((s, i) => (
<Fragment key={s}>
{i > 0 && ", "}
<code>{s}</code>
</Fragment>
))}
</div>
)}
{entry.disabledByDefault && (
<div>
<strong>Disabled by default</strong>
</div>
)}
</div>
)}
{entry.syntaxes.length > 0 && (
<div>
Syntax:
<ul className="list-unstyled">
{entry.syntaxes.map((syntax, index) => (
<li key={index}>
{formatPattern(syntax.pattern, entry.defaultSpokenForm)}:{" "}
{formatPattern(syntax.description)}
</li>
))}
</ul>
</div>
)}
{entry.examples.length > 0 && (
<div>
Examples:
<ul className="list-unstyled">
{entry.examples.map((example, index) => (
<li key={index}>
<code>
"
{formatPattern(example.spokenForm, entry.defaultSpokenForm)}
"
</code>
: {example.description}
</li>
))}
</ul>
</div>
)}
</>
);
}
function formatPattern(
pattern: string,
defaultSpokenForm?: string,
): React.ReactNode[] {
return pattern.split(/(<[\w ]+>)/gu).map((part, index) => {
if (part.startsWith("<") && part.endsWith(">")) {
if (part === "<spokenForm>") {
return defaultSpokenForm ?? "???";
}
return <code key={index}>{part}</code>;
}
return part;
});
}